cf.completefrontend

Predict the outputMedium

How do Map and Set compare keys in this snippet?

What does this log?
const map = new Map();
map.set(1, "number");
map.set("1", "string");
map.set(NaN, "nan");
map.set({}, "object");
map["color"] = "red";
 
console.log(map.size);
console.log(map.get(1), map.get("1"), map.get(NaN));
console.log(map.get({}));
console.log(map.has("color"), map.color);
console.log(new Set([0, -0, NaN, NaN, "0"]).size);

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…