What is the output of the following code? “`js const obj = {x: 1}; Object.defineProperty(obj, ‘y’, { value: 2, writable: false, enumerable: false }); console.log(Object.keys(obj)); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following code? “`js const obj = {x: 1}; Object.defineProperty(obj, ‘y’, { value: 2, writable: false, enumerable: false }); console.log(Object.keys(obj)); “`

Key points

  • `Object.keys()` returns only enumerable properties
  • Non-enumerable properties are not included in the output
  • The 'y' property is not enumerable in this code
  • The 'x' property is enumerable and will be included in the output

Ready to go further?

Related questions