What are Symbols used for in JavaScript?
By FrontendPro Editorial Team Updated 8/8/2026
Answer
Symbols in JavaScript are a new primitive data type introduced in ES6 (ECMAScript 2015). They are unique and immutable identifiers that are primarily used for object property keys to avoid name collisions. These values can be created using the Symbol(...) function, and each Symbol value is guaranteed to be unique, even if they have the same key/description. Symbol properties are not enumerable in for...in loops or Object.keys(), making them suitable for creating private/internal object state.
let sym1 = Symbol();
let sym2 = Symbol("myKey");
console.log(typeof sym1); // "symbol"
console.log(sym1 === sym2); // false, because each symbol is unique
let obj = {};
let sym = Symbol("uniqueKey");
obj[sym] = "value";
console.log(obj[sym]); // "value"
Note: The Symbol() function must be called without the new keyword. It is not exactly a constructor because it can only be called as a function instead of with new Symbol().
Read the detailed answer on GreatFrontEnd which allows progress tracking, contains more code samples, and useful resources.
