0Pricing
JavaScript Academy · Lesson

The Global Symbol Registry

Share symbols with Symbol.for and keyFor.

A Shared Registry

The global symbol registry lets you create symbols that are shared across your whole program by key, instead of always being unique.

const a = Symbol.for("app.id")
const b = Symbol.for("app.id")
console.log(a === b)

Symbol.for

Symbol.for looks up a symbol by a string key in the registry. If one exists it is returned; otherwise a new one is created and stored.

const token = Symbol.for("token")
console.log(token.description)

All lessons in this course

  1. Creating Unique Symbols
  2. Symbols as Object Keys
  3. The Global Symbol Registry
  4. Well-Known Symbols
← Back to JavaScript Academy