News for hackers. Stuff that matters.
Re:Advanced console.log Tips and Tricks (2020) by Stratoscope on Wednesday June 16, 2021 @03:21AM (#27525812)
console.log is not asynchronous. For example, this code:

  let a = "hello";
  console.log( a );
  let a = "goodbye";
will always reliably print "hello", not "goodbye".

What you're referring to is the fact that when you expand an object or array in the console, then you see the contents of that object or array at the time you expand it, not as it originally existed when console.log() was called.

This is why alessioalex's sibling comment is so useful. By logging the output from JSON.stringify(), you are logging a string whose value will not change.

Re:Advanced console.log Tips and Tricks (2020) by metafunctor on Wednesday June 16, 2021 @04:05AM (#27526087)
That's... what asynchronous means. The call to console.log() will return before the console output is actually produced.
Re:Advanced console.log Tips and Tricks (2020) by MatthewMob on Wednesday June 16, 2021 @04:11AM (#27526117)
No. It means that when you invoke `console.log` in a browser it "logs" a reference to an object instead of serialising it.

This log is still synchronous, but when you expand it in the console its properties are dereferenced and may be different from when the original log was made. The log, however, is still instantaneous and synchronous.

Re:Advanced console.log Tips and Tricks (2020) by metafunctor on Wednesday June 16, 2021 @06:20AM (#27526846)
OK, agreed. That's an important distinction. The console log will synchronously receive a reference to an object; later if you expand something in the log window it shows you the current state.
Re:Advanced console.log Tips and Tricks (2020) by mjbrusso on Wednesday June 16, 2021 @07:05AM (#27527111)
I would say the argument is lazy evaluated.
Re:Advanced console.log Tips and Tricks (2020) by genezeta on Wednesday June 16, 2021 @04:32AM (#27526223)
To add to the MatthewMob's explanation, see this: https://imgur.com/a/vUTCumu
Re:Advanced console.log Tips and Tricks (2020) by voiper1 on Wednesday June 16, 2021 @05:28AM (#27526565)
Thanks! I figured it meant that, but nice to see it without having to mess around.