Class Symbol

Symbol is a primitive data type that can serve as object properties. Symbol instance can be created explicitly or via a global registry, see for(String).

API Version:

Available from version 21.2.

ConstantDescription
hasInstance: SymbolThe symbol used by instanceof.
isConcatSpreadable: SymbolThe symbol used by Array.concat(Object...).
iterator: SymbolThe symbol used by for...of.
match: SymbolThe symbol used by String.match(RegExp).
replace: SymbolThe symbol used by String.replace().
search: SymbolThe symbol used by String.search(RegExp).
species: SymbolThe symbol used to create derived objects.
split: SymbolThe symbol used by String.split().
toPrimitive: SymbolThe symbol used to convert an object to a primitive value.
toStringTag: SymbolThe symbol used by Object.toString().
unscopables: SymbolThe symbol used by with.
ConstructorDescription
Symbol()Creates a new symbol.
Symbol(String)Creates a new symbol.
MethodDescription
static for(String)Obtains a symbol from the global registry.
static keyFor(Symbol)Returns the key within the global symbol registry under which the given symbol is stored.

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

hasInstance: Symbol

The symbol used by instanceof.


isConcatSpreadable: Symbol

The symbol used by Array.concat(Object...).


iterator: Symbol

The symbol used by for...of.


match: Symbol

The symbol used by String.match(RegExp).


replace: Symbol

The symbol used by String.replace().


search: Symbol

The symbol used by String.search(RegExp).


species: Symbol

The symbol used to create derived objects.


split: Symbol

The symbol used by String.split().


toPrimitive: Symbol

The symbol used to convert an object to a primitive value.


toStringTag: Symbol

The symbol used by Object.toString().


unscopables: Symbol

The symbol used by with.


Symbol()

Creates a new symbol. Note that it must be called without new. Symbols created via this method are always distinct.


Symbol(description: String)

Creates a new symbol. Note that it must be called without new. Symbols created via this method are always distinct.

Parameters:

  • description - A description for this symbol.

static for(key: String): Symbol

Obtains a symbol from the global registry. If no symbol exists for the key within the registry a new symbol is created and stored in the global registry.

Parameters:

  • key - The key for a symbol within the global registry.

Returns:

  • The found or newly created symbol.

API Version:

Available from version 21.2.


static keyFor(symbol: Symbol): String

Returns the key within the global symbol registry under which the given symbol is stored.

Parameters:

  • symbol - The symbol to look for.

Returns:

  • The key for the given symbol if the symbol is known to the global registry, else return undefined.