You should use === strict comparision
NaN === undefined # False
Null === undefined # False
NaN === Null # False
But: NaN === NaN # False
NaN is special in that it doesn't have a real value, so comparing it to itself doesn't return true. Essentially, NaN is equal to nothing, not even NaN . ... NaN is the same as boolean false . Of course false === false , so the expression evaluates to true.
You may consider it easy :
isNaN(null); // false
Whenever you pass a nonnumerical value as the argument of the isNaN method, it tries to convert it to a number. After conversation, if it evaluates to a number, then returns false. Otherwise returns true.
console.log(+null); // 0
A little '+' in front of anything (i.e string) makes it a number. As you can see, the conversation of null to a number is 0. And isNaN(0) is false. Therefore the final answer is false. However,
console.log(+undefined); // NaN
You can see after the conversation, it gives us NaN. And isNaN(NaN) is of course true.
The other two were explained by Muhammad :))
Arb Rahim Badsa Muhammad when converting both null and undefined using == give same value.but why converting using isNaN give different value or how it compare other with NaN value.while converting null to number gives 0 then why not converting undefined to number gives 0 when they have same content(null==undefined)