I need to compare two numeric values for equality in Javascript. The values may be NaN as well. I\'ve come up with this code:
NaN
if (val1 == val2 |
Found another way using Array.prototype.includes MDN link. Apparently, [NaN].includes(NaN) returns true for NaN.
function IsActuallyNaN(obj) { return [obj].includes(NaN); }
Or we can go with davidchambers' solution which is much simpler.
function IsActuallyNaN2(obj) { return obj !== obj; }