What is the output of the following code? “`js const obj = {a: 1}; const copy = obj; copy.a = 99; console.log(obj.a); “`

JavaScript Associate Medium

JavaScript Associate — Medium

What is the output of the following code? “`js const obj = {a: 1}; const copy = obj; copy.a = 99; console.log(obj.a); “`

Key points

  • Assigning an object to another variable creates a reference, not a new object
  • Modifying the reference object will reflect changes in the original object
  • JavaScript objects are passed by reference, not by value

Ready to go further?

Related questions