JS Built-ins
ObjectObject.definePropertyintermediate

Object.defineProperty() β€” non-enumerable property

πŸ“– 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() β€” enumerable: false

A non-enumerable property is hidden from Object.keys, for...in, and JSON.stringify, but can still be read directly.

Challenge: Implement addHidden(obj, key, val) that defines a non-enumerable property.

const o = {}
addHidden(o, '_id', 42)
o._id             // β†’ 42
Object.keys(o)    // β†’ []  (not visible)
πŸ’‘ Hints (2)
  • β€’ `enumerable: false` hides the property from iteration methods like `Object.keys`.
  • β€’ `Object.getOwnPropertyNames` still lists non-enumerable properties.