The Symbol in JavaScript is the new type of DataType. What they actually do?

The Symbol is a new primitive type introduced in ES6. It’s introduced in ES6. Symbols are completely unique identifiers. Just like their primitive counterparts (Number, String, Boolean), they can be created using the factory function Symbol () which returns a Symbol. 

List of Symbol Features:-
1.      The Symbol is used to create a unique identifier and every symbol value returned from Symbol() is unique.
2.      The symbol does not auto convert to strings.
3.      Symbols are great to be used as the key in objects.
4.      Two Symbols with the same description is never equal.
5.      The data type symbol is a primitive data type.
6.      While iterating over Objects, Symbol as the key won't be accessible. They become hidden properties. But, Object.assign({}) , Symbol will also get copied.

Syntax: - Symbol([description])
A description of the symbol which can be used for debugging but not to access the symbol itself

const symbol1 = Symbol();
const symbol2 = Symbol(35);
const symbol3 = Symbol('Anil');

console.log(typeof symbol1);
// expected output is : "symbol"

// expected output is : "Symbol(Anil)"

console.log(Symbol('Anil') === Symbol('Anil'));
// expected output is : false

Do we really need symbols?
Yes, Use symbols when your requirement is one of these:
1.      Enum
2.      Name Clashes
3.      Privacy
4.      Protocols
5.      And so on.

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2 Powered by Blogger.