Symbol
In one line
A Symbol is a primitive value that is guaranteed to be unique, often used as object property keys to avoid collisions.
In simple words
A Symbol is a primitive type introduced in ES6. Every Symbol is unique — Symbol('x') === Symbol('x') is false even with the same description. This makes Symbols ideal for creating non-colliding object property keys.
Symbols are often used to add 'hidden' properties to objects that won't conflict with other properties or show up in normal iteration. Well-known Symbols (like Symbol.iterator and Symbol.toPrimitive) define core language behaviors — for example, Symbol.iterator makes an object iterable.
Symbols do not show up in for...in loops or Object.keys(). To access them, use Object.getOwnPropertySymbols(). To create a shared symbol across code, use Symbol.for('key') (the global symbol registry).
Example
const s1 = Symbol("id");
const s2 = Symbol("id");
console.log(s1 === s2); // false — unique
const obj = { [s1]: "secret" };
console.log(Object.keys(obj)); // [] — symbol hiddenEach Symbol is unique. Symbol-keyed properties don't appear in Object.keys.
Related terms
Related Resources
Related Lessons
- Data Types
Learn about Symbols.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.