Back to Lessons

JavaScript Symbol Data Type

April 5, 2026

Symbol (ES6)

Primitive type for unique identifiers.

Symbol Examples

let sym1 = Symbol("description");
let sym2 = Symbol("description"); // Different symbols
console.log(sym1 === sym2); // false

let obj = {
    [sym1]: "secret value",
    name: "John"
};

console.log(obj[sym1]); // "secret value"

// Global registry
let globalSym = Symbol.for("shared");
let sameSym = Symbol.for("shared"); // Same symbol

Key Points

  • Always unique, even same description.
  • Property keys prevent naming conflicts.
  • Symbol.iterator for custom iteration.
  • Symbol.for() global symbol registry.