What is a Symbol?
The Symbol data type in JavaScript is a unique and immutable primitive data type introduced in the ES6 standard to solve the problem of creating hidden and unique object property identifiers.
The main feature of symbols is that even if two symbols are created with the exact same description or without one altogether, they are still strictly not equal to each other. For example, the call `Symbol('desc')` will always return a unique value, and the condition `Symbol('desc') !== Symbol('desc')` will always evaluate to true.
In practice, symbols are most often used to create unique object property keys that will not conflict with other properties. This is especially useful when developing libraries or adding metadata hidden from standard iteration loops like `for...in`.
For situations where you need to use the same symbol in different parts of an application, there is a global symbol registry. It is accessed through special methods for working with the global namespace:
In addition, JavaScript has a set of so-called well-known symbols, which are built into the language and allow developers to modify the behavior of built-in object mechanisms.
A striking example of such a symbol is `Symbol.iterator`, which defines the default iterator for an object. By implementing this method, a developer gets the opportunity to use their own custom object in a `for...of` loop.