Symbol function JavaScript

JavaScript Symbol function is used to identify the properties of an object.

Note:

  • It always returns a unique value.
  • A symbol value may be used as an identifier for object properties.
  • Like numbers or strings, Symbols are also immutable.

Syntax:

Symbol([description])   

Parameters: description: It represents the symbol description.

JavaScript Symbol Methods

for() Method: Use: To find out the existing symbol in a runtime-wide symbol registry with the provided key.

keyFor() Method: Use: To search for the key of the global symbol.

toString() Method: Use: To retrieve a string representation of an object.

JavaScript Symbol Properties

Symbol.hasInstance:  It is used to check if a constructor object recognizes an object as its instance or not.

Symbol.isConcatSpreadable: It is used to check if an object is flattened to its array elements.

Symbol.match: It is used to check the match of a regular expression against a string.

Symbol.prototype: It represents the Symbol constructor’s prototype.

Symbol.replace: It is used to replace the matched sub-strings of a string.

Symbol.search: it returns the index within a string that matches the regular expression.

Symbol.split: It is used to split a string at the indices that match a regular expression.

Symbol.toStringTag: It creates the default string description of an object.

Symbol.unscopables: An object value whose property names are excluded from the environment.

Please follow and like us:
Content Protection by DMCA.com