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
- Creating Unique Symbols
- Symbols as Object Keys
- The Global Symbol Registry
- Well-Known Symbols