Example 1 — Basic Use
Attach a Symbol key and list it with getOwnPropertySymbols.
var id = Symbol("id");
var user = { name: "Ada" };
user[id] = 101;
console.log(Object.keys(user));
console.log(Object.getOwnPropertySymbols(user));
console.log(user[Object.getOwnPropertySymbols(user)[0]]); How It Works
- Create a Symbol
Symbol("id")makes a unique key. The description"id"is only a label. - Store a value Assign with bracket notation:
user[id] = 101. - List symbol keys
Object.keysshows onlyname.getOwnPropertySymbolsreturns the Symbol.

