Introduction
As JavaScript continues to evolve, it has been adding features that extend its capabilities. One such addition is the Symbol, a unique, immutable data type introduced in ECMAScript 2015.

In this article, we will delve into the concept of the Symbol, including its creation, use cases, properties, and methods.
Understanding the Symbol
In JavaScript, a Symbol is a unique and immutable data type. When you create a Symbol, JavaScript ensures it's unique, even if two Symbols have the same description.
To create a Symbol, you use the Symbol() function. This function can accept an optional string parameter that represents the Symbol's description. However, this description doesn't impact the Symbol's uniqueness.
let symbol1 = Symbol();
let symbol2 = Symbol("symbol description");
let symbol3 = Symbol("symbol description");
Even though symbol2 and symbol3 have the same description, they are not the same.
Using Symbols as Object Keys
One of the main uses of Symbols is as keys in an object. Because every Symbol is unique, they allow us to create properties in objects that won't clash with any other property or method, thereby avoiding bugs that could arise from overwriting data.
let employee = {};
let id = Symbol('id');
employee[id] = 'E1001';
In the above code, the id Symbol is used as a property key in the employee object. The Symbol ensures the uniqueness of the property.
The Symbol.for and Symbol.keyFor Methods
JavaScript's Symbol object includes the Symbol.for(key) and Symbol.keyFor(sym) methods. The Symbol.for(key) method searches for existing Symbols with the given key and returns it if found. If not found, it creates a new Symbol with the given key.
let symbol1 = Symbol.for("employee");
let symbol2 = Symbol.for("employee");
console.log(symbol1 === symbol2);
/Outputs:
True

The Symbol.keyFor(sym) method returns a string representing the key for the Symbol sym in the global Symbol registry.
let symbol1 = Symbol.for("employee");
console.log(Symbol.keyFor(symbol1));
Outputs:
"employee"
