JS Built-ins
ObjectObject.getOwnPropertyDescriptorbeginner

Object.getOwnPropertyDescriptor() β€” check specific flags

πŸ“– Usage Example
// Inspect a single property's descriptor
const obj = { x: 42 }
Object.getOwnPropertyDescriptor(obj, 'x')
// β†’ { value: 42, writable: true, enumerable: true, configurable: true }

Use Object.getOwnPropertyDescriptor() to retrieve the descriptor object that describes a property's attributes.

Object.getOwnPropertyDescriptor() β€” inspecting flags

You can use the returned descriptor to check individual flags like enumerable and configurable.

Challenge: Implement isEnumerable(obj, key) that returns whether the own property key is enumerable.

isEnumerable({ a: 1 }, 'a')  // β†’ true (normal property)
πŸ’‘ Hints (2)
  • β€’ Use optional chaining: `descriptor?.enumerable === true`.
  • β€’ If the property does not exist, `undefined === true` is `false`.