JS Built-ins
ObjectObject.getOwnPropertyDescriptorintermediate

Object.getOwnPropertyDescriptor() β€” inherited returns undefined

πŸ“– 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() β€” own only

The method only looks at own properties. Inherited properties return undefined even if accessible via the prototype chain.

Challenge: Implement inheritedIsUndefined() that creates an object with a prototype that has protoKey, checks that getOwnPropertyDescriptor returns undefined for it, and returns that result.

inheritedIsUndefined() // β†’ true
πŸ’‘ Hints (1)
  • β€’ `getOwnPropertyDescriptor` strictly checks own properties β€” the prototype chain is ignored.