What does the following code log? const obj = { a: 1 }; const copy = Object.assign({}, obj); copy.a = 99; console.log(obj.a);

JavaScript Developer Medium

JavaScript Developer — Medium

What does the following code log? const obj = { a: 1 }; const copy = Object.assign({}, obj); copy.a = 99; console.log(obj.a);

Key points

  • Object.assign creates a shallow copy
  • Changes to the copy do not affect the original object
  • The value of obj.a remains 1
  • The log statement outputs the value of obj.a

Ready to go further?

Related questions