0

What is going on in the following js code?

let testObj={x:[1,2,3],y:[1,2,3]};
console.log(testObj);
testObj.x=[1,2,2]
testObj.y=[1,1,1]
console.log(testObj);

Output

{x: Array(3), y: Array(3)}
x: (3) [1, 2, 2]
y: (3) [1, 1, 1]
__proto__: Object

{x: Array(3), y: Array(3)}
x: (3) [1, 2, 2]
y: (3) [1, 1, 1]
__proto__: Object

Surely the first console.log should have run before I re-assigned the attributes of testObj? What is happening?

Vishal Jain
  • 443
  • 4
  • 17

0 Answers0