Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil) . Junte-se a nós e ajude a fazer o trabalho!
A Symbol is a primitive data type whose instances are unique and immutable. In some programming languages they are also called atoms.
In JavaScript, Symbol is one of the primitive values and the Symbol
object is a wrapper around a Symbol primitive.
Symbol can have an optional description, but for debugging purposes only.
Symbol type is a new feature in EcmaScript 6 (es6) and there is no EcmaScript 5 equivalent for symbol.
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 ]