Symbols
Learn the new data type introduced by ES2015 - symbols. Learn how to use its creating function and its values.
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 ...