Skip to content

Instantly share code, notes, and snippets.

@nulayuhz
Last active August 29, 2015 14:09
Show Gist options
  • Save nulayuhz/a4af81b3b6f56a300c72 to your computer and use it in GitHub Desktop.
Save nulayuhz/a4af81b3b6f56a300c72 to your computer and use it in GitHub Desktop.
Async Console
https://github.com/getify/You-Dont-Know-JS/blob/master/async%20&%20performance/ch1.md#async-console
there are some browsers and some conditions that console.log(..)
does not actually immediately output what it's given.
The main reason this may happen is because I/O is a very slow and blocking
part of many programs (not just JS).
So, it may be more performant (from the page/UI perspective) for a browser to
handle console I/O asynchronously in the background.
var a = {
index: 1
};
// later
console.log( a ); // ??
// even later
a.index++;
it's possible this same code could run in a situation where the browser felt
it needed to defer the console I/O to the background, in which case it's possible
that by the time the object is represented in the browser console, the a.index++
has already happened, and it shows { index: 2 }.
@nulayuhz
Copy link
Author

"Note: If you run into this rare scenario, the best option is to use breakpoints in your JS debugger instead of relying on console output. The next best option would be to force a "snapshot" of the object in question by serializing it to a string, like with JSON.stringify(..)."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment