Symbol

Symbol(description) Symbol.for(key)

Creates a unique value – each call of Symbol() gives a different one, even with the same description. It is used as a key of properties that do not collide with others and are not listed in Object.keys() or JSON.

Parameters

  • description – optional, a text for debugging (symbol.description).
  • Symbol.for(key) – returns a shared symbol from the global registry (the same key = the same symbol).

Return value

A value of the type symbol.

Examples

const id = Symbol('id');
const user = { name: 'Jane', [id]: 42 };
console.log(user[id], Object.keys(user), JSON.stringify(user));
console.log(Symbol('id') === Symbol('id'), Symbol.for('app') === Symbol.for('app'), id.description);

Output:

42 [ 'name' ] {"name":"Jane"}
false true id

Custom iteration of an object with a for...of loop through Symbol.iterator:

const range = {
  from: 1,
  to: 4,
  *[Symbol.iterator]() {
    for (let i = this.from; i <= this.to; i++) yield i;
  },
};
console.log([...range]);

Output:

[ 1, 2, 3, 4 ]

Things to watch out for

  • A symbol cannot be converted to a string by concatenation ('' + symbol throws a TypeError) – use String(symbol) or description.
  • Properties with a symbol are not secret: Object.getOwnPropertySymbols() returns them.

Browser support

Baseline – widely available: in all major browsers since September 2015, considered widely available since March 2018. Since version: Chrome 38, Firefox 36, Safari 9; Node.js 0.12.0. As of October 2026 (MDN browser-compat-data).

Related:
typeof
String()
Map