JS: How Map Determines Uniqueness of Keys
How Map Determines Uniqueness of Keys
The equality test used for determining whether 2 keys in a
Map Object
is the Triple Equal Operator except treatment of NaN.
NaN === NaN
return false
, but for map object, NaN
is considered same as any NaN
.
// NaN === NaN is false console.log((NaN === NaN) === false); // for map object, NaN key are considered the same const xx = new Map(); xx.set(NaN, "y1"); xx.set(NaN, "y2"); console.log(xx.size === 1); console.log(xx.get(NaN) === "y2");
How Set Determines Uniqueness
The equality test used for determining whether 2 values in a set is the same as ===
,
except treatment of NaN
(not a number).
NaN === NaN
return false
, but for set object, NaN
is considered same as any NaN
.
// equality test used for determining whether 2 values in the set is the same as ===, except treatment of NaN // NaN === NaN is false console.log((NaN === NaN) === false); // but for set object, NaN is same as any NaN const ss = new Set([NaN, NaN]); console.log(ss.size === 1);
JavaScript, Map Object
- JS: Map Object Tutorial
- JS: Difference, Object vs Map
- JS: Literal Expression for Map
- JS: Nested Map
- JS: Iterate Map Object
- JS: Convert Object to Map 🚀
- JS: Convert Map to Object 🚀
- JS: Map Equality 🚀
- JS: Map Filter 🚀
- JS: Swap Key Value of Map 🚀
- JS: Sort Map 🚀
- JS: Truncate Map 🚀
- JS: Map Substract 🚀
- JS: How Map Determines Uniqueness of Keys
- JS: Map Object
- JS: Map Constructor
- JS: Map.prototype