Member-only story

Javascript Do you know the Symbol type?

An introduction to the Symbol type introduced by ES2015

--

Among the numerous novelties that ES6 (also known as ECMAScript 2015) brought, there is one that I would say has gone quite unnoticed, especially if we compare its popularity with other features such as the spread operator or the tagged templates of which I already spoke in other articles:

As the title suggests, I am referring to the definition of the new Symbol type that comes to join the rest of the primitive types:string , number , boolean , null and undefined. So in this article I intend to list the main characteristics of this new type as well as its main uses.

Let’s see them!

The type Symbol

First of all to understand the Symbol type is to turn to the definition made of it in the Mozilla documentation:

The data type symbol is a primitive data type. The Symbol() function returns a value of type symbol, has static properties that expose several members of built-in objects, has static methods that expose the global symbol registry, and resembles a built-in object class, but is incomplete as a constructor because it does not support the syntax "new Symbol()".

To be honest, the first time I read this definition, the truth is that I stayed the same as I was, so I will add one that will give us a better idea of what the Symbol type really is:

The Symbol type allows us to obtain values that cannot be re-created, that is, they are unique and immutable identifiers.

According to this definition, the one provided by MDN makes more sense since since the values created as Symbol will be unique, we can use them to identify properties of…

--

--

Gerardo Fernández
Gerardo Fernández

Written by Gerardo Fernández

Entre paseo y paseo con Simba desarrollo en Symfony y React

No responses yet

Write a response