Symbol Type
Symbol Type
Unique and immutable data type to be used as an identifier for object properties.
Symbol can have an optional description, but for debugging purposes only.
ECMAScript 6 — syntactic sugar: reduced | traditional
Symbol("foo") !== Symbol("foo")
const foo = Symbol()
const bar = Symbol()
typeof foo === "symbol"
typeof bar === "symbol"
let obj = {}
obj[foo] = "foo"
obj[bar] = "bar"
JSON.stringify(obj) // {}
Object.keys(obj) // []
Object.getOwnPropertyNames(obj) // []
Object.getOwnPropertySymbols(obj) // [ foo, bar ]
ECMAScript 5 — syntactic sugar: reduced | traditional
// no equivalent in ES5