JS Built-ins
ObjectObject.definePropertyadvanced

Object.defineProperty() β€” configurable: false

πŸ“– Usage Example
// Define a property with a custom descriptor
const obj = {}
Object.defineProperty(obj, 'name', {
  value: 'Alice',
  writable: false,
  enumerable: true,
})

Use Object.defineProperty() to add or modify a property with precise control over its writability, enumerability, and configurability.

Object.defineProperty() β€” configurable: false

When configurable: false, the property cannot be deleted and its descriptor cannot be changed (except loosening writable from true to false).

Challenge: Implement lockProperty(obj, key, val) that defines a non-configurable, non-writable property.

const o = {}
lockProperty(o, 'id', 1)
delete o.id   // silently fails
o.id          // β†’ 1
πŸ’‘ Hints (2)
  • β€’ Set both `writable: false` and `configurable: false` to fully lock a property.
  • β€’ In sloppy mode, attempting to delete or reassign silently fails.