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
What is printed?
const m = new Map();
m.set(NaN, 'first');
m.set(NaN, 'second');
console.log(m.size, m.get(NaN));
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
:: Copyright KIRUPA 2024 //--