Reading the MDN documentation where we talk about the primitive data Symbol
for more that I read and reread I do not understand what would be a use case for that element more than to iterate Symbol.iterator
.
The documentation says that its use is for debug purposes, but even with this I do not understand why to use Symbol
to debug if there is console.log()
or debugger
.
I understand that it is a primitive data and, therefore, immutable. In the examples I have seen that they do something like the following:
var sym = Symbol('Llave'),
obj = {
[sym]: 'valor'
};
console.log(obj[sym]); // valor
console.log(obj['Llave']); // undefined
Why use a Symbol
? if you can use a traditional key (key: value).
Sources: