Javascript. Maps and Weak Maps

The Javascript Map object was added to solve some of the limitations that Javascript had. Discover all its features!

Gerardo Fernández
5 min readSep 14, 2020

I recently published a “javascript recipe” in which I talked about some of the uses we can give to the Map object and what its advantages are with respect to using flat Javascript objects.

Given that the “recipe” format falls short, I have decided to write this article going more deeply into both the Javascript Map object and the WeakMap object, which has interesting implications at the performance level.

Let’s go there!

The Map object

Before looking at the differences between Map and flat objects, let’s first see how to create and use these types of objects.

First of all, we can create a Map as follows:

const map = new Map();

If we want to initialize it directly from its constructor we can pass an array of “key-value” arrays:

--

--

Gerardo Fernández

Entre paseo y paseo con Simba desarrollo en Symfony y React