This primitive type is useful for so-called "private" and/or "unique" keys.

Using a symbol, you know no one else who doesn't share this instance (instead of the string) will not be able to set a specific property on a map.

Example without symbols:

var map = {};
setProp(map);
setProp2(map);

function setProp(map) {
  map.prop = "hey";
}
function setProp2(map) {
  map.prop = "hey, version 2";
}

In this case, the 2nd function call will override the value in the first one.

However, with symbols, instead of just using "the string prop", we use the instance itself:

var map = {};
var symbol1 = Symbol("prop");
var symbol2 = Symbol("prop"); // same name, different instance – so it's a different symbol!
map[symbol1] = 1;
map[symbol2] = 2; // doesn't override the previous symbol's value
console.log(map[symbol1] + map[symbol2]); // logs 3
Answer from Ven on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Symbol
Symbol - JavaScript | MDN
Because symbols are the only primitive data type that has reference identity (that is, you cannot create the same symbol twice), they behave like objects in some way.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-symbol-reference
JavaScript Symbol Reference - GeeksforGeeks
July 23, 2025 - In JavaScript, the Symbol is a primitive data type introduced in ES6. It is created using the `Symbol()` function, which returns a unique symbol value each time it is called. Symbols are immutable and unique, making them useful for creating ...
🌐
Programiz
programiz.com › javascript › symbol
JavaScript Symbol (with Examples)
The JavaScript ES6 introduced a new primitive data type called Symbol. Symbols are immutable (cannot be changed) and are unique.
🌐
web.dev
web.dev › learn › javascript › data-types › symbol
Symbol | web.dev
As with other primitive data types, symbols inherit methods and properties from their prototype.
🌐
Playcode
playcode.io › javascript › symbols
Playcode
Try this online JavaScript Playground with instant live preview and console. Easy & Fast. Experiment yourself.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Symbol type
So, to summarize, a symbol is a “primitive unique value” with an optional description. Let’s see where we can use them. ... Most values in JavaScript support implicit conversion to a string. For instance, we can alert almost any value, and it will work.
🌐
Medium
medium.com › @rahul.jindal57 › symbol-data-type-in-javascript-395b876b9dd3
Symbol Data type in JavaScript | by Rahul Jindal | Medium | Medium
March 26, 2023 - Symbols are a unique data type in JavaScript that returns a Symbol value or Symbol when called. A new and immutable value is returned each time Symbol is called.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_symbol_object.htm
JavaScript - The Symbol Object
In JavaScript, Symbol is a primitive data type and it was introduced in ECMAScript 6 (ES6). It can be created using the 'Symbol' constructor.
🌐
W3docs
w3docs.com › learn-javascript › symbol-types.html
Deep Dive into JavaScript Symbol Types
Symbols, introduced in ECMAScript 2015 (ES6), are a unique and immutable data type that are primarily used to add unique property keys to objects. This guide explores Symbols, their practical applications, and how they enhance JavaScript development ...
🌐
Geekster
geekster.in › home › symbol data type in js
Symbol Data Type In JS With Example
June 11, 2024 - The Symbol data type stands out for its unique guarantee: each symbol created using the Symbol() function is distinct, even if they share the same description. In the realm of JavaScript, where data types play a pivotal role in determining code ...
🌐
TypeScript
typescriptlang.org › docs › handbook › symbols.html
TypeScript: Documentation - Symbols
Starting with ECMAScript 2015, symbol is a primitive data type, just like number and string.
🌐
W3Schools
w3schools.com › js › js_datatypes.asp
JavaScript Data Types
// Strings let color = "Yellow"; let lastName = "Johnson"; // Number let length = 16; let weight = 7.5; // BigInt let x = 1234567890123456789012345n; let y = BigInt(1234567890123456789012345) // Boolean let x = true; let y = false; // Object const person = {firstName:"John", lastName:"Doe"}; // Array object const cars = ["Saab", "Volvo", "BMW"]; // Date object const date = new Date("2022-03-25"); // Undefined let x; let y; // Null let x = null; let y = null; // Symbol const x = Symbol(); const y = Symbol(); In programming, data types is an important concept. To be able to operate on variables, it is important to know something about the type. Without data types, a computer cannot safely solve this: ... Does it make any sense to add "Volvo" to sixteen? Will it produce an error or will it produce a result? ... When adding a number and a string, JavaScript will treat the number as a string.
🌐
Stack Overflow
stackoverflow.com › questions › 69713810 › what-are-use-cases-for-the-symbol-data-type-in-javascript
object - What are use cases for the Symbol data type in JavaScript? - Stack Overflow
i know that Symbol is a new immutable ... Symbol('foo') === Symbol('foo') // false ... Symbol data type was introduced by keeping "private properties" in mind....
🌐
Flavio Copes
flaviocopes.com › javascript-symbols
JavaScript Symbols
July 26, 2019 - Symbol is a primitive data type of JavaScript, along with string, number, boolean, null and undefined. It was introduced in ECMAScript 2015, so just a few years ago.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Data_structures
JavaScript data types and data structures - JavaScript | MDN
All of this requires conventions and creates an unnecessary maintenance burden. Use strings for textual data. When representing complex data, parse strings, and use the appropriate abstraction. A Symbol is a unique and immutable primitive value and may be used as the key of an Object property (see ...
🌐
Dot Net Tutorials
dotnettutorials.net › home › javascript symbol
JavaScript Symbol Primitive Data Type with Examples
February 23, 2021 - In JavaScript, Symbol is a new primitive data type introduced in ES6. It is a primitive data type along with the string, number, Boolean, null and undefined.
Top answer
1 of 3
17

Symbol is used to create a totally unique, one-of-a-kind identifier. It's use is precisely for the example you list.

Even if you call Symbol with the same string, the instances will be different. This allows different libraries (which may be used at the same time) to define keys which may be used at the same time.

For example, imagine two libraries using a common name to define something on window or global (or for illustration, the fake global door):

const door = {};
// from library 1
door.cake = () => console.log('chocolate');
// from library 2
door.cake = () => console.log('vanilla');

// your code
door.cake();

In this example, the first libraries code is lost because it was unintentionally given the same name as the first.

Now, if they both use Symbol, then even if they are named the same, you can still access both (assuming they export Symbol somehow):

const door = {};
// library 1
const cake1 = Symbol('cake');
door[cake1] = () => console.log('chocolate');
// library 2
const cake2 = Symbol('cake');
door[cake2] = () => console.log('vanilla');
// your code
door[cake1]();
door[cake2]();

Both are still accessible.

That is a bit of an oversimplification, but it illustrated the point.

In a more practical usage, these are used for things such as importing modules. The modules may end up with the same name, but that's okay because they'll have unique symbols associated with them, which makes them uniquely accessible as long as your have the Symbol objects.

As for when to use them yourself... it's probably going to be pretty rare. You'll mainly want to use them any time you have a way to provide the Symbol but need other things to remain unique. I've only used these directly in a few narrow circumstances where the created element may end up the same.

For example, if you were making an object using names as the key, you might have duplicate names. Without symbols, the objects would override one other. With symbols, they'll all remain.

const people = {};
people[Symbol('bob')] = { name: 'Bob Smith' };
people[Symbol('bob')] = { name: 'Bob Jones' };
2 of 3
7

From the documentation:

Every symbol value returned from Symbol() is unique.

That means === comparisons will fail because they're not identical.

If you want a unique identifier of some sort that can be given a descriptive, if otherwise irrelevant name, then Symbol might be useful.

🌐
GreatFrontEnd
greatfrontend.com › questions › quiz › what-are-symbols-used-for
What are `Symbol`s used for in JavaScript? | Quiz Interview Questions with Solutions
September 5, 2021 - Symbols in JavaScript are a new primitive data type introduced in ES6 (ECMAScript 2015). They are unique and immutable identifiers that is primarily for object property keys to avoid name collisions.
🌐
DEV Community
dev.to › waelhabbal › javascript-symbols-a-deep-dive-1fkn
JavaScript Symbols: A Deep Dive - DEV Community
July 1, 2024 - In JavaScript, a Symbol is a unique and immutable primitive value that can be used to create unique identifiers for objects, properties, or methods. Unlike strings or numbers, Symbols are not coerced to a different type and cannot be converted ...