Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Symbol Complete Reference

Improve Article
Save Article
  • Last Updated : 18 Jan, 2023
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.

Syntax:

[Symbol.peoperty](string)

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

Javascript




<script>
   // 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
   console.log(Array3);
  
   // Calling Symbol.isConcatSpreadable symbol
   Array2[Symbol.isConcatSpreadable] = false;
   Array3 = Array1.concat(Array2);
  
   // Printing the concatenated array
   // after calling of Symbol.isConcatSpreadable symbol
   console.log(Array3);
</script>

Output:

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

The complete list of JavaScript Symbol is listed below:

JavaScript Symbol Static Properties:

Properties

Description 

hasInstanceDetermine if a given constructor object recognizes the object as its instance.
isConcatSpreadableGiven object should be flattened to its array elements while using the Array.prototype.concat() method.
JavaScript Symbol.matchRegular expression against a string and this function is called using
replaceReplace the matched substring of a string.
searchReturns the index within a string that matches the regular expression. 
splitSpecify the method that splits a string at the indices that match a regular expression.
toStringTagCreation of the default string description of an object.
unscopablesSpecify an object value of whose own and inherited property names are excluded from the environment bindings.

JavaScript Static methods

 Methods 

Description

for()The Symbol.for() is used to search for the given symbol
keyFor()This key is retrieved from the global symbol registry.

JavaScript Symbol Instance Properties:

 Properties

Description

descriptionReturn the optional description of the specified symbol objects.

JavaScript Symbol Instance Methods:

MethodsDescription
toString()convert the specified symbol object into the string.
valueOf()Return the primitive value of a given symbol object.
@@toPrimitive()Convert a given symbol object to a primitive value.
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!