Javatpoint Logo
Javatpoint Logo

JavaScript Symbol

The JavaScript Symbol is a function that is used to identify the object properties.

Points to remember

  1. A Symbol() method always return a unique value.
  2. A symbol value may be used as an identifier for object properties.
  3. Symbols are immutable, just like numbers or strings.
  4. Symbols cannot be typecasted to primitive data types.

Syntax

Parameters

description: It is optional. We can pass string as an argument.

JavaScript Symbol Property

Let's see the list of JavaScript Symbol properties with their description.

Symbol.hasInstance It is used to determine if a constructor object recognizes an object as its instance.
Symbol.isConcatSpreadable It is used to configure if an object should be flattened to its array elements.
Symbol.match It is a method to identify the matching of a regular expression against a string.
Symbol.prototype It is used for produce the prototype for the symbol constructor.
Symbol.replace It replace matched substring of a string.
Symbol.search It returns the index within a string that matches with the regular expression.
Symbol.split It splits a string at the indices that match the regular expression.
Symbol.toPrimitive It is used to convert an object to its equivalent primitive value.
Symbol.unscopables It is a well-known object property whose property name are excluded from with environment.

JavaScript Symbol Methods

Let's see the list of JavaScript Symbol Method with their description.

Symbol.for() It is used to search for existing symbol in a runtime-wide symbol registry with the provided key and returns if it is found. Otherwise new symbol gets created with this key.
Symbol.keyFor() It uses the global symbol registry to look up the key for the symbol. So it doesn't work for non-global symbols. If the symbol is not global, it won't be able to find it and returns undefined.
Symbol.toString() It is used to return a string representation of an object.

Next TopicJavaScript Symbol




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA