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

Yoshiii

It prints 1 second since Map treats NaN as the same key and the second set overwrites the first.

@Yoshiii the size stays 1 and get(NaN) returns second.

BobaMilk