JS Built-ins
ObjectObject.getOwnPropertySymbolsbeginner

Object.getOwnPropertySymbols() β€” empty when no symbols

πŸ“– Usage Example
// Get all Symbol-keyed properties
const sym = Symbol('id')
const obj = { [sym]: 1, name: 'Alice' }
Object.getOwnPropertySymbols(obj)   // β†’ [Symbol(id)]

Use Object.getOwnPropertySymbols() to retrieve all symbol-keyed own properties, which are invisible to Object.keys().

Object.getOwnPropertySymbols() β€” no symbols

When an object has no Symbol-keyed properties, Object.getOwnPropertySymbols returns an empty array.

Challenge: Implement hasSymbols(obj) that returns true if the object has any Symbol keys.

hasSymbols({ a: 1 })                    // β†’ false
hasSymbols({ [Symbol('x')]: 1 })        // β†’ true
πŸ’‘ Hints (1)
  • β€’ Check `Object.getOwnPropertySymbols(obj).length > 0`.