Possible Duplicate:
Is Chrome's JavaScript console lazy about evaluating arrays?
Open up Chrome Developer Tools and type in:
var a = [];console.log(a);a.push(1);console.log(a);
You would expect this to output something like
[]
[1]
But instead it outputs
[1]
[1]
The behaviour is the same for
var a = [];console.log(a);a[0] = 1;console.log(a);
Can anyone explain this behaviour?
Running Chrome on OS X. Same behaviour on 32bit Windows 7.
EDIT: The behaviour is the same regardless of whether the statements are on the same line or not. I have simply provided them on a single line to make it easy to test.
Putting
var a = [];
console.log(a);
a.push(1);
console.log(a);
in a file then running it yields the same behaviour.
EDIT x 2 See: http://jsfiddle.net/9N4A6/ if you don't feel like making a file to test.