Example 1 — Is This Key Stored?
Mark one product as in stock, then ask about two products and about the first one again after removing it.
const stock = new Map();
stock.set("mug", 12);
console.log(stock.has("mug")); // true
console.log(stock.has("cup")); // false
stock.delete("mug");
console.log(stock.has("mug")); // false How It Works
- A stored key answers true.
stock.set("mug", 12)adds the entry, sohas("mug")finds it. - An unknown key answers false.
"cup"was never stored.has()only reports this; it does not add the key. - Removing changes the answer. After
delete("mug")the entry is gone, so the samehas("mug")call now saysfalse.

