What is printed?
const m = new Map();
m.set(NaN, 'first');
m.set(NaN, 'second');
console.log(m.size, m.get(NaN));
- 2 first
- 2 second
- 1 second
- 1 first
0
voters
MechaPrime
What is printed?
const m = new Map();
m.set(NaN, 'first');
m.set(NaN, 'second');
console.log(m.size, m.get(NaN));
MechaPrime
It prints 1 second. Map treats NaN as equal to NaN (SameValueZero), so the second set overwrites the first and the size stays 1.
:: Copyright KIRUPA 2024 //--