Overview

let id1 = Symbol();
let id2 = Symbol("id"); // id2 is a symbol with the description "id"
console.log(id1 == id2); // false
let id = Symbol("id");

let user = { 
	name: "John" 
};
user[id] = "ID Value";

let user = {
  [id]: 1000,
  name: "John"
};
let obj = {
  1: "test" // same as "1": "test"
};
console.log(obj["1"]);
console.log(obj[1]);

Global Symbol Registry

// Read from the global registry
let id = Symbol.for("id"); // if the symbol did not exist, it is created
let idAgain = Symbol.for("id"); // Read it again
console.log(id === idAgain); // true

Symbol.keyFor

let sym1 = Symbol.for("name");
let sym2 = Symbol.for("id");

console.log(Symbol.keyFor(sym1)); // name
console.log(Symbol.keyFor(sym2)); // id
console.log(Symbol.keyFor(Symbol.for("name"))); // name, global symbol
console.log(Symbol.keyFor(Symbol("name2"))); // undefined, the argument isn't a global symbol