JS Built-ins
ObjectObject.definePropertiesintermediate

Object.defineProperties() β€” value and writable together

πŸ“– Usage Example
// Define multiple property descriptors at once
const obj = {}
Object.defineProperties(obj, {
  x: { value: 1, writable: true, enumerable: true },
  y: { value: 2, writable: false, enumerable: true },
})

Use Object.defineProperties() to define multiple properties with fine-grained descriptors in a single call.

Object.defineProperties() β€” data descriptors

A data descriptor defines both value and writable. This exercises combining multiple property options in one call.

Challenge: Implement setupCounter(obj) that uses Object.defineProperties to add a count property (value: 0, writable: true) and a step property (value: 1, writable: false).

const o = {}
setupCounter(o)
o.count += o.step  // β†’ 1
πŸ’‘ Hints (2)
  • β€’ `count` needs `writable: true` so you can increment it.
  • β€’ `step` with `writable: false` acts as a constant.