Bizarre console.log behaviour in Chrome Developer Tools [duplicate] Bizarre console.log behaviour in Chrome Developer Tools [duplicate] google-chrome google-chrome

Bizarre console.log behaviour in Chrome Developer Tools [duplicate]


Try this instead:

var a = []; console.log(a.toString()); a.push(1); console.log(a.toString());

It's not that the order of evaluation is strange, I bet, but that the conversion of the objects to printable form happens after the statements are all executed, at the point when Chrome is ready to actually dump out the log.


Same behavior here with Win7 on a x64 machine. My guess is that the log method holds a reference to a and queues the calls that happen to be in a single line.

EDIT It's not a Chrome/ium issue alone, I have witnessed the same with Firebug. As I said console logging must be queued in some ways.


At least with arrays, you can clone the array for each log call:

var a = [];console.log([].concat(a));a.push(1);console.log([].concat(a));

For objects, I recommend JSON:

var a = {};console.log(JSON.stringify(a));a[0]=1;console.log(JSON.stringify(a));