[Solved] Why javascript object value is changed? [duplicate]
You are pointing y to the reference of x which itself is pointing to the object {a:1,b:2}. So in memory it is: x –> {a:1,b:2} After you do y = x, it becomes: y –> x –> {a:1,b:2} Or to put it simply: x –> {a:20,b:2} ^ | y ——- Now when you do y.a … Read more