4 ms·
I recently learned of a pretty surprising chrome console interpreter bug that was reported as early as 2010[1], fixed by 2012, and at some point seems to have d
by wcarss 9y ago
I recently learned of a pretty surprising chrome console interpreter bug that was reported as early as 2010[1], fixed by 2012, and at some point seems to have degraded again.
console.log lazily evaluates complex values at first-expand-time, rather than eagerly at print-time, and there is no built-in facility to automatically expand them at print-time. To see this being weird, try logging a changing array inside of a loop, then expand the first log after the loop completes. It will show the array state at click-time, rather than at the point in time the log statement executed. Subsequent changes to the array will not be reflected.
People have been complaining for years about this, but it seems to be widely accepted as just-the-way-it-is[2-4], with the most common workaround being JSON.stringifying logged objects.
I'm mostly shocked that I only noticed I was being bit by it a little while ago.
1 - (2010, shows 2012 fix) https://bugs.webkit.org/show_bug.cgi?id=35801 https://bugs.webkit.org/show_bug.cgi?id=35801
2 - (2010, w/ edits to note 2012 fix) https://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays https://stackoverflow.com/questions/4057440/is-chromes-javas...
3 - (2014) https://stackoverflow.com/questions/23392111/console-log-async-or-sync https://stackoverflow.com/questions/23392111/console-log-asy...
4 - (2016) https://taoalpha.github.io/blog/2016/04/21/tech-lazy-evaluation-of-console-log/ https://taoalpha.github.io/blog/2016/04/21/tech-lazy-evaluat...