Learn JavaScript

Create Symbol

We can use the Symbol() function to create a new symbol every time we execute it.

In the example given below, we are creating two symbols and comparing them. The result is false as each time we execute the function, it creates a new symbol.

This function can also accept a description as an argument. Adding the description does not change its behaviour.

In the example given above, the name1 and name2 symbols have the same description. But they are not equal. Therefore, the result is false.

We can use the .description property to show the description of the symbol.