symbol datatype in javascript | consfused when and where to use symbol?

preview_player
Показать описание
A “symbol” represents a unique identifier.

A value of this type can be created using Symbol():

Symbols allow us to create “hidden” properties of an object, that no other part of code can accidentally access or overwrite.

Symbols are skipped by for…in

Symbol is used when:
“Hidden” object properties. If we want to add a property into an object that “belongs” to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in for..in, so it won’t be accidentally processed together with other properties. Also it won’t be accessed directly, because another script does not have our symbol. So the property will be protected from accidental use or overwrite.
Рекомендации по теме
Комментарии
Автор

Great video, thanks for clearing the concept.

aheteshamshaikh
Автор

But you can use other means to find hidden keys. So Symbol wasn't devised for that purpose.

dankierson