JavaScript Symbols Using Symbol.for() to create global, shared symbols

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


The Symbol.for method allows you to register and look up global symbols by name. The first time it is called with a given key, it creates a new symbol and adds it to the registry.

let a = Symbol.for('A');

The next time you call Symbol.for('A'), the same symbol will be returned instead of a new one (in contrast to Symbol('A') which would create a new, unique symbol that happens to have the same description).

a === Symbol.for('A') // true


a === Symbol('A') // false

Got any JavaScript Question?