They greatly help us to have name conflicts. Anytime you want to create a property in a unique way, when you need to find a symbol.
Look at my example
const bert = Symbol('Bert');
'Bert'
Note: this is not a value, this is what they called a descriptor, because the character itself is just a unique identifier. So if you visualized what the character would be, you might be able to visualize it something like this “sdfasdfa2342134987fgsdfgsdf9808fsfgsd” absolute unique character, so you can be sure that it will never replace any other piece of code in it.
What is cool about this if I create a second character like
const person = Symbol('Bert')
You can see that I used Burt again. Will they be the same because I described them as one and the same?
const bert = Symbol('Bert'); const person = Symbol('Bert'); console.log(bert); console.log(person); console.log(bert === person); console.log(bert == person);

This can be useful if you are creating an object of your class.
const classRoom = { 'Mia' : { grade: 50, gender: 'female' }, 'Gilbert': { grade: 80, gender: 'male' }, 'Gilbert' { grade: 80, gender: 'male' }, };
But then you have another one named Gilbert, so you come across names. So imagine if you are working with millions and millions of data. Thus, instead of using the name of people or using some unique identifier, we can use a symbol for their names.
const classRoom = { [Symbol('Mia')] : { grade: 50, gender: 'female' }, [Symbol('Gilbert')]: { grade: 80, gender: 'male' }, [Symbol('Gilbert')]: { grade: 80, gender: 'male' }, };
Another thing related to symbols is that they are not listed, which means that we cannot loop them if I
for (const person in classRoom) { console.log(person); }
I get nothing.
If you want to access all of your characters because they contain some information that you want to receive, you can use the object method.
const syms = Object.getOwnPropertySymbols(classRoom); const data = syms.map(sym => classRoom[sym]); console.log(data);
source share