JavaScript Symbol Object
Symbol creates unique values that can be used as property keys that never clash with other keys. Built-in symbols such as Symbol.iterator let you customize how objects behave.
Description
A Symbol is a primitive value that is guaranteed to be unique. Every call to Symbol() returns a new symbol, even with the same description, so symbols make good property keys when you need to add a property that can't collide with anything else. Symbol-keyed properties are skipped by for...in, Object.keys() and JSON.stringify().
Symbol.for(key) returns a shared symbol from a global registry, the same one each time for the same key. JavaScript also has well-known symbols, such as Symbol.iterator, Symbol.asyncIterator and Symbol.toPrimitive, which objects can define to plug into language features like for...of. Symbol can't be used with new.
Symbols also make it possible to add metadata to objects you don't own without risk of clashing with their existing or future properties. Object.getOwnPropertySymbols() and Reflect.ownKeys() list symbol keys, so they aren't truly private; use #private class fields for real privacy. A symbol's description property returns the text it was created with, which is helpful when debugging.
Syntax
Symbol()
Symbol(description)
Symbol.for(key)Static properties
| Name | Description |
|---|---|
Symbol.iterator | Symbol.iterator is the symbol used to make an object iterable. |
Example
Browser Support
The following information will show you the current browser support for the Symbol object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





