Andrea Carron
Andrea Carron

Reputation: 1021

console.debug() not working correctly

I noticed that the console.debug() doesn't always works as expected (at least in google chrome). For example, in the following code the console.debug ( dirs ) works fine until the alert ( dirs ) function works. But when I say to chrome to stop the alert windows from the page, the console.debug( dirs ) begin to shows an empty array ([ ]). If I print the array in a for-loop, however, I see it's not really empty.

var dirs = [ 0, 1, 2, 3 ];
console.debug ( dirs );
alert ( dirs );

The code is called through the

setInterval ( "function_with_the_code()", 20 )

Upvotes: 1

Views: 410

Answers (1)

c69
c69

Reputation: 21517

Chrome / Safari WebInspector, and Opera Dragonfly output live objects.

so, the code

for(var a =[], i = 0; i < 5; i++ ) { a.push(i), console.log( a ); }

will output

Array [0, 1, 2, 3, 4]
Array [0, 1, 2, 3, 4]
Array [0, 1, 2, 3, 4]
Array [0, 1, 2, 3, 4]
Array [0, 1, 2, 3, 4]

but,

for(var a =[], i = 0; i < 5; i++ ) { a.push(i), console.log( a + '' ); }

will output

0
0,1
0,1,2
0,1,2,3
0,1,2,3,4

Don't remember about IE F12, Firebug or Native Firefox Console.

Upvotes: 1

Related Questions