Example 1 — Empty a Map
Create a Map with three tags, empty it, and look at the size, the return value, and a lookup.
const tags = new Map([
["js", true],
["css", true],
["html", true]
]);
console.log(tags.size); // 3
const result = tags.clear();
console.log(tags.size); // 0
console.log(String(result)); // undefined
console.log(tags.has("js")); // false How It Works
- Start with values. The Map is created from three pairs, so its
sizeis 3. - Clear it.
tags.clear()removes everything. It returnsundefined, soresultprints asundefined. - Nothing is left. The size is 0 and
has("js")isfalse, because the old entries are gone.

