Open In App

JavaScript Symbol Reference

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In JavaScript, the Symbol is a primitive data type introduced in ES6. It is created using the `Symbol()` function, which returns a unique symbol value each time it is called. Symbols are immutable and unique, making them useful for creating property keys that are guaranteed to be unique across different objects. They are often used to define non-enumerable object properties.

Syntax:

[Symbol.property](string)

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

JavaScript
// 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);

Output
[ 1, 2, 3, 4, 5, 6 ]
[ 1, 2, 3, [ 4, 5, 6, [Symbol(Symbol.isConcatSpreadable)]: false ] ]

The complete list of JavaScript Symbol is listed below:

JavaScript Symbol Constructor: In JavaScript, a constructor gets called when an object is created.

ConstructorDescription
Symbol()Used to create a symbol object

JavaScript Symbol Properties: A JavaScript property is a member of an object that associates a key with a value.

  • Static Property: A static property is a property that has the same value for the entire class.

Properties

Description 

asyncIteratorIt sets an object as async iterable
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.
iteratorIt makes an element easier to use in for..of loop
matchIt identifies matching of a Regular Expression to a string
matchAllIt returns Regular Expression that matches the String
replaceReplace the matched substring of a string.
searchReturns the index within a string that matches the regular expression. 
speciesIt is used to create a derived object from a function-valued property 
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.
  • Instance Properties: An instance property is a property that has a new copy for every new instance of the class.

 Properties

Description

constructorReturn the string constructor function for the object.
descriptionReturn the optional description of the specified symbol objects.

JavaScript Symbol Methods: JavaScript methods are actions that can be performed on objects. There are two types of Symbol methods in JavaScript.

  • Static Method: If the method is called using the symbol class itself then it is called a static method.

 Methods 

Description

for()The Symbol.for() is used to search for the given symbol
keyFor()This key is retrieved from the global symbol registry.
  • Instance Method: If the method is called on an instance of a Symbol then it is called an instance method.
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.


Next Article

Similar Reads