Skip to content
Related Articles

Related Articles

JavaScript Symbol Complete Reference

Improve Article
Save Article
  • Last Updated : 23 Nov, 2022
Improve Article
Save Article

The symbol is a data type of primitive data type. The Symbol() function returns the symbol value type. The value returned from Symbol() is unique.



Example: JavaScript code to show the working of this function. 


   // Creating some arrays
   const Array1 = [1, 2, 3];
   const Array2 = [4, 5, 6];
   // Calling concat() function
   let Array3 = Array1.concat(Array2);
   // Printing the concatenated array
   // Calling Symbol.isConcatSpreadable symbol
   Array2[Symbol.isConcatSpreadable] = false;
   Array3 = Array1.concat(Array2);
   // Printing the concatenated array
   // after calling of Symbol.isConcatSpreadable symbol


 Array [1, 2, 3, 4, 5, 6]
 Array [1, 2, 3, Array [4, 5, 6]]

The complete list of JavaScript Symbol is listed below:

Static Properties:

JavaScript Symbol Static properties


JavaScript Symbol.hasInstance PropertyThe Symbol.hasInstance is an inbuilt property in JavaScript which is used to determine if a given constructor object recognizes the object as its instance.
JavaScript Symbol.isConcatSpreadable symbolThe Symbol.isConcatSpreadable is a well-known symbol used to configure if a given object should be flattened to its array elements while using the Array.prototype.concat() method.
JavaScript Symbol.match PropertyThe Symbol.match property is used to identify the matching of a regular expression against a string and this function is called using
JavaScript Symbol.replace PropertyThe Symbol.replace property replace the matched substring of a string.
JavaScript PropertyThe property returns the index within a string that matches the regular expression. 
JavaScript Symbol.split PropertyThe Symbol.split property is used to specify the method that splits a string at the indices that match a regular expression.
JavaScript Symbol.toStringTag symbolThe Symbol.toStringTag is used in the creation of the default string description of an object.
JavaScript Symbol.unscopables PropertiesThe Symbol.unscopables property is used to specify an object value of whose own and inherited property names are excluded from the environment bindings.

Static methods

JavaScript Static methods 


JavaScript Symbol.for() functionThe Symbol.for() is is used to search for the given symbol
JavaScript Symbol.keyFor() functionThe Symbol.keyFor() is used to retrieve the key which has been shared with the given symbols and this key is retrieved from the global symbol registry.

Instance Properties:

JavaScript Symbol Instance properties


JavaScript symbol.description propertyThe symbol.description is an inbuilt property in JavaScript which is used to return the optional description of the specified symbol objects.

Instance Methods:

JavaScript Symbol Instance methodsDescription
JavaScript symbol.toString() functionThe symbol.toString() is to convert the specified symbol object into the string.
JavaScript symbol.valueOf() functionThe symbol.valueOf() is used to return the primitive value of a given symbol object.
JavaScript symbol.@@toPrimitive() functionThe symbol.@@toPrimitive() is used to convert a given symbol object to a primitive value.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!