In Chrome, If an Array or an Object Changes after Logged in the Console, and If It Is Not Expanded Yet, the Expanded Result Reflects the Newer Version

·

1 min read

Array

Please look at the example below and follow the steps below.

  1. Open the console.

  2. Click the button several times (more than three times). Then, number 1 will be added to the array and the array will be logged in console. Be careful not to expand the results.

  3. Expand the results which have only one or two elements.

If you followed the steps, you may have noticed the expanded array has more elements they are supposed to have. This is because it reflects current status of the array.

The Chrome says it really does. If you expand, you can check a blue tooltip. If you put the cursor on it, it says like this.

"This value was evaluated upon first expanding. It may have changed since then."

If you want to maintain the original forms, you can do it by expanding before clicking.

Object

The browser treats objects in the same way as arrays.

Check it through the example below and by ways that I mentioned above.