This primitive / value type was added in ES 2015
Symbols are objects.
Can be used as an identifier for object properties
They are globally, unique values
No two symbols are ever the same.
let mySymbol = Symbol();
When you pass in a text string, the text string becomes the label for the symbol.
let mySymbol = Symbol('text');
console.log( mySymbol.toString() ); // 'text'
You cannot see the actual value, it is always hidden.
Symbols can be reused
This creates an identical symbol
var mySymbol = Symbol.for('text');
Symbol is not a constructor
You cannot use the new keyword when creating a symbol.
The following line of code will generate an error
let mySymbol = new Symbol(); // ERROR
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext