What is the output of the following? “`js const obj = {}; obj.a = 1; Object.defineProperty(obj, ‘b’, {value: 2, enumerable: false}); const copy = {…obj}; console.log(copy); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following? “`js const obj = {}; obj.a = 1; Object.defineProperty(obj, ‘b’, {value: 2, enumerable: false}); const copy = {…obj}; console.log(copy); “`

Key points

  • Spread operator only copies enumerable properties
  • Object.defineProperty can make properties non-enumerable
  • Non-enumerable properties are not copied by the spread operator

Ready to go further?

Related questions