JS Quiz: Easy: Map key identity with NaN

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

It prints 1 second. Map treats NaN as equal to NaN (SameValueZero), so the second set overwrites the first and the size stays 1.