I don't understand the output of this code. Ask the expert to help me analyze it.

    let a = {n: 1}
    let b = a;
    a.x = a = {n: 2}
    console.log(a.x);
    console.log(b.x);

the second output b.x I can understand, because an and b are the same reference,

but I really don"t understand the output of one. Ask God to help me analyze

.
Nov.20,2021

https://codeshelper.com/a/11.


axi5 is an expression that returns a value

>  a=5
<  5

so b=a=5 is assigned from right to left.
then a.x = a = {n: 2} is equivalent to

a = {n:2} // -> a : {n:2}
a.x = a   // -> a : {n:2,x:{n:2}}

that's about what it means.



    [][1]


let a = {n: 1} //
let b = a;  //  
a.x = a = {n: 2} //
   --  a = {n: 2} //a
   --  a.x = a // {n: 2}; a
console.log(a.x); //a
console.log(b.x); //b
//aa

understand the order in which the js engine reads connected equations

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-1b3b1a9-2c275.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-1b3b1a9-2c275.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?