obj with a property
prop we can refer to it like so:
obj.prop. A symbol can have a string describing it, and the string can have spaces and other special characters not found in a normal object property identifier. If we have a Symbol
symb and it is used as a property of obj, we can refer to obj's symb like so:
There is no literal Symbol representation like
10 is a literal number and
'ten' is a literal string. You just need to know that creating a Symbol gives it a unique value. You explicitly create symbols with
Symbol('optional description') (but not by using
Symbols are used to identify an object property, like literal strings do. But they lie in a separate namespace (
Object.getOwnPropertySymbols()) from literal string identifiers (
Object.getOwnPropertyNames()). They won't overlap or override each other and you have to use the two separate methods above to get the lists of them. You can create many symbols with the same or no description and they are all unique and can all be used in an object as distinct keys.
Use Symbols when you want to add new properties to objects without possibly conflicting with existing (string identifier) properties.