JS Built-ins
ObjectObject.getOwnPropertySymbolsbeginner

Object.getOwnPropertySymbols() β€” Symbol created with Symbol()

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

Each call to Symbol(description) creates a unique symbol. Two symbols with the same description are not equal.

Challenge: Implement uniqueSymbols() that creates two symbols with the same description 'test' and returns whether they are equal.

uniqueSymbols() // β†’ false (each Symbol() call is unique)
πŸ’‘ Hints (1)
  • β€’ `Symbol()` always creates a brand-new unique value, even with the same description string.