An object, first console.log and then change the attribute value of the object, the printed result has changed?

as follows:

   var obj = {
    a: [1]
   }
   console.log(obj);
   obj.a = [2];

result:

clipboard.png

a:


clipboard.png

Why is there such a difference? solve

Sep.04,2021

this is because of console.log/dir/. When this kind of method outputs an object, it will show the latest state of the object in memory; the address of the memory is the original value and cannot be modified, so the value of an in the output result of the object has been modified to the latest value


because you haven't unfolded below. If it's not unfolded, it's just a snapshot of console at that time.

and you have to understand that the function you use is log log, which is a text string. Although the browser can do some dynamic, it is mainly static, right? If you want to see the dynamic one, let's find debug.

Menu