What is the result of the following code snippet? const obj = { x: 10 }; Object.defineProperty(obj, ‘x’, { writable: false, configurable: false }); Object.freeze(obj); obj.x = 20; console.log(obj.x);

Web Development Hard

Web Development — Hard

What is the result of the following code snippet? const obj = { x: 10 }; Object.defineProperty(obj, ‘x’, { writable: false, configurable: false }); Object.freeze(obj); obj.x = 20; console.log(obj.x);

Key points

  • Non-strict mode assignments to non-writable properties fail silently.
  • Object.freeze makes all properties non-writable.
  • Existing property descriptors are respected during freezing.

Ready to go further?

Related questions