0

Possible Duplicate:
Is Chrome's JavaScript console lazy about evaluating arrays?

I'm not really sure if this is to do with JS or Chrome or console.log or what but would be interested to get an answer.

I am coding in Eclipse and running in Chrome using console.log to do some debugging. My code is enclosed in the JQuery .ready() method.

I define a simple array var arr = [1,2,3,4,5]; then log the array and its first value which gives me (as I would expect) the output [1, 2, 3, 4, 5] and 1.

I then update the first value using arr[0] = 12; and log the same the array and the first value again. My code now looks like this:

var arr = [1,2,3,4,5];
console.log(arr);
console.log(arr[0]);
arr[0] = 12;
console.log(arr);
console.log(arr[0]);

And get the following output:

[12, 2, 3, 4, 5]
1
[12, 2, 3, 4, 5]
12

My question is, why do the first and third lines both log with the updated first value when the first log is called before that value is entered?

Is this just a lag with calling the log method or is there something else going on here?

Thanks for your help :)

Community
  • 1
  • 1
popClingwrap
  • 3,919
  • 5
  • 26
  • 44
  • It's the chrome console "lag" – Esailija Aug 06 '12 at 16:41
  • See: http://stackoverflow.com/questions/4198912/bizarre-console-log-behaviour-in-chrome-developer-tools, and: http://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays – Radu Aug 06 '12 at 16:42

0 Answers0