Overview
Symbols are a new primitive type introduced in ES6.
Symbols are completely unique identifiers. Just like its primitive counterparts, t...
For further actions, you may consider blocking this person and/or reporting abuse
Nice article, but I think there is a typo.
const foo = {
name: 'Ben',
age: 25,
}
for(let val of foo) {
console.log(val) // Ben, 25
}
This should throw TypeError, because objects are not iterable. Maybe you meant for...in ?
developer.mozilla.org/en-US/docs/W...
I still didn't get why symbols are used. can you tell me why they are used?
TLDR: They're used because they are unique. That's it.
Imagine them like any other string except you can guarantee it's unique.
(Also when used as object keys they're enumerable which is nice)
Symbol.for() means Symbols are truly not unique.
Combined with the
Symbol
iterator Object.getOwnPropertySymbols objectSymbols
can be exposedOhh! now I get it. 😀