Categories
Web Development

A console.log issue in Google Chrome

Found an interesting issue in Google Chrome today and have reported it to bugs.chromium.org.

The issue relates to change and print object value in a loop, you can reproduce it by executing the following code in Chrome Console.

var book = {info:{}};
for(var i = 0; i < 3; i++){
    book.info.id = i;
    console.log(book);
}

The expected result “id” in the object book should be 0, 1, 2 however it prints 2, 2, 2 as below. The code executes as expected in Safari.

I assume the issue is encountered by the cache rule of speeding up console.log only checks whether the top level of the variable is changed in a loop so caused the issue.

UPDATE:

Got the reply from Chromium that they won’t fix it:

Working as intended. If you hover over the [ i ] icon for more information, it will tell you that the variable content was evaluated at the point when you expanded the log entry.

Leave a Reply

Your email address will not be published. Required fields are marked *