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
but
a === Symbol('A') // false