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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a83e-2c217.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a83e-2c217.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?