Global Registry With Symbol
Learn how to create or fetch keys for Symbols in the global registry.
We'll cover the following...
Uniqueness of Symbol
s
When we create a Symbol
using the Symbol()
function, the argument passed to it has no significance, and each call to Symbol()
creates a unique Symbol
.
Proof by example
Let’s quickly verify this behavior with an example.
Press + to interact
'use strict';//START:CODEconst name = 'Tom';const tom = Symbol(name);const jerry = Symbol('Jerry');const anotherTom = Symbol(name);console.log(tom);console.log(typeof(tom));console.log(tom === jerry);console.log(tom === anotherTom);//END:CODE
Explanation
- We created three
Symbol
s. Two of them were created using the same argumentname
. - However, since the arguments passed to the function have no
Access this course and 1400+ top-rated courses and projects.