JS Built-ins
Symbolforbeginner

Symbol.for() β€” same key returns same Symbol

πŸ“– Usage Example
Symbol.for('foo') === Symbol.for('foo')  // β†’ true
Symbol('foo')    === Symbol('foo')       // β†’ false

Symbol.for() looks up a global registry β€” the same key always returns the identical symbol.

Symbol.for(key)

Symbol.for(key) looks up a Symbol in the global registry. If not found, it creates one. Calling it twice with the same key returns the same Symbol.

Challenge: Verify that Symbol.for('foo') === Symbol.for('foo').

πŸ’‘ Hints (1)
  • β€’ Symbol.for() uses a global registry keyed by string.