What is the use of Symbol in this code

<script type="text/javascript>                
var name1 = Symbol("Description 1");
                var name2 = Symbol("Description 2");
                name1 = "John";
                name1 = "Smith";
                console.log(name1);
</script>

The symbol provides a unique value that cannot be accidentally mistaken for anything else.
In the code that you posted, they aren’t doing anything useful, and might as well not even be there.

There’s some good into about symbols in the Symbols and Their Uses article.

Thanks :slight_smile:

Symbol() function returns a unique value from every symbol value and has static properties, static methods and resembles a built in object class. They are a new primitive data type available which allow you to create unique identifiers

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.