Symbol API

Unique and immutable primitive values as object property keys.

Symbol is a primitive data type where values are unique and immutable. Symbols are often used as identifiers for object properties to avoid name clashes, especially in environments where objects from different sources need to coexist.

Symbols are created with the Symbol() function, and each symbol value returned by Symbol() is unique. Symbols can be used as identifiers for object properties and are useful for defining a set of constants, implementing private or internal properties, or creating hooks in metaprogramming.

Every symbol value returned from Symbol() is unique, even if the symbols have the same description. The Symbol.for() method creates a symbol in a global symbol registry, and Symbol.keyFor() retrieves a symbol key from the registry.

11 Total 5 Methods 6 Properties 8 Statics
  Show all

Symbol(…)

Creates a new Symbol object.Symbol([description])

Symbol[asyncIterator]

A symbol used to define the default async iterator method for an object.Symbol[asyncIterator]

description

Returns the optional description of a Symbol object.s.description

Symbol.for(…)

Returns a symbol from the global symbol registry with the given key, or creates it if it doesn't exist.Symbol.for(key)

Symbol[hasInstance]

A symbol used to define if an object is an instance of a constructor.Symbol[hasInstance]

Symbol[iterator]

A symbol used to define the default iterator method for an object.Symbol[iterator]

Symbol.keyFor(…)

Returns the key from the global symbol registry for the given symbol.Symbol.keyFor(symbol)

Symbol[toPrimitive]

A symbol used to convert an object to a primitive value.Symbol[toPrimitive]

toString()

Returns a string representing the Symbol object.s.toString()

Symbol[toStringTag]

A symbol used to define the default string description of an object.Symbol[toStringTag]

valueOf()

Returns the primitive value of the Symbol object.s.valueOf()

Symbol.keyFor(…)

staticmethod

Returns the key from the global symbol registry for the given symbol. Symbol.keyFor(symbol)

Arguments

symbol – The symbol to find the key for.

You seem to be offline. App may not work.