Symbol Static Methods

Symbol.for(key)

Searches, in the global symbol registry, for a symbol with the given key and returns it if found. Otherwise a new symbol gets created in the global symbol registry with this key. Well-known symbols are not symbols stored in the global registry, ie. local.

Symbol.keyFor(sym)

Retrieves a shared symbol key from the global symbol registry for the given symbol.


var gs = Symbol.for('my global symbol');

console.log(gs);
console.log(gs === Symbol.for('my global symbol'));

console.log(Symbol.keyFor(gs));
console.log(Symbol.keyFor(Symbol('local')));
console.log(Symbol.keyFor(Symbol.iterator));

Symbol(my global symbol) true my global symbol undefined undefined