JS Built-ins
SymbolkeyForbeginner

Symbol.keyFor() β€” consistent round-trip

πŸ“– Usage Example
const key = 'userId'
const s = Symbol.for(key)
Symbol.keyFor(s) === key   // β†’ true

Symbol.for(key) and Symbol.keyFor(sym) are inverse operations β€” a perfect round-trip.

Symbol.keyFor Round-Trip

A symbol registered with Symbol.for(key) can always be recovered: Symbol.keyFor(Symbol.for(key)) === key.

Challenge: Verify the round-trip is consistent.

πŸ’‘ Hints (1)
  • β€’ Symbol.for and Symbol.keyFor are inverse operations.