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

JS Quiz answer: Option 3 (C).

Correct choice: 1 second

Why:
Map treats NaN keys as the same key for equality.

Go deeper:

Keyboard Events In Javascript

First-answer leaderboard

  1. @emmawalter5 - 12 (firsts) :trophy:
  2. @kirupa - 8 (firsts)
  3. @Apexcodes - 6 (firsts)
  4. @adnanahmed - 2 (firsts)