console.log() and google chrome

Posted by Lorenzo C on Stack Overflow See other posts from Stack Overflow or by Lorenzo C
Published on 2012-06-26T09:07:25Z Indexed on 2012/06/26 9:15 UTC
Read the original article Hit count: 201

Filed under:
|
|

I'm testing a library and I use console.log() function to visualyze values. There is a strange behaviour of Google Chrome (in other browser like Firefox it doesn't happend).

If I try to store strings in Array object when I log them, sometimes values appears undefined.

Code example (item.name is a string)

var arrayItemsSearch = [item.name];
var itemRedrawName = [item.name];
console.log("arrayItemsSearch: ", arrayItemsSearch);
console.log("itemRedrawName: ", itemRedrawName);

Firefox output is correct

arrayItemsSearch: ["elem[0]"]
itemRedrawName: ["elem[0]"]

Chrome output is not correct

arrayItemsSearch:  [undefined × 1]
itemRedrawName:  ["elem[0]"] 

Is this a Chrome bug? Or is this beacuse in Javascript strings are immutable objects and so something that I don't understand goes wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-chrome