Symbols
Explore JavaScript Symbols, a primitive and unique data type introduced in ES2015 that serve primarily as keys for object properties. Understand their behavior, creation, usage as non-enumerable keys, global symbols, and practical use cases for extending objects without interfering with existing properties.
We'll cover the following...
The symbol is an entirely new data type introduced in ES2015. It’s primitive, like numbers and strings. Its behavior is quite odd and it serves a small use case. Let’s dive right in.
Introduction
Every symbol is unique. Running the Symbol() function produces dynamically unique values every time. Both equality operators, == and ===, will always return false when comparing two symbols. This is vital to its behavior and its purpose.
Symbols are anonymous. That is, we can’t ever see the value that they contain. It’s hidden in the JavaScript engine. This makes their uses quite limited.
In fact, the only practical purpose a symbol has is serving as a key for a property in an object. Before ES2015, the only data ...