JS Built-ins
Symbolforintermediate

Symbol.for() β€” keyFor retrieves the key

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

Symbol.keyFor() retrieves the registration key used with Symbol.for().

Symbol.keyFor

Symbol.keyFor(sym) returns the key used to register a global symbol.

Challenge: Verify that Symbol.keyFor(Symbol.for('app')) === 'app'.

πŸ’‘ Hints (1)
  • β€’ Symbol.keyFor only works for globally registered symbols.