NaN - The global NaN property is a special value that means Not-A-Number (not a number).
The curious thing is that it is not possible to perform operations of comparison with this almost mystical property. Featuring a nonreflective feature where NaN === NaN is false.
I made below a javascript code executable just to test the concept, but could be any programming language.
var spans = document.querySelectorAll('span');
for(var i in spans){
var span = spans[i];
if(span && typeof span.getAttribute == 'function'){
var exp = span.getAttribute("data-evaluate");
console.log(exp, eval(exp));
span.innerHTML = "Expr: "+ exp + " ------------ :> " + eval(exp);
}
}
<span data-evaluate="true"></span><br> <!-- eval control -->
<span data-evaluate="isNaN(NaN)"></span><br><!-- NaN control -->
<span data-evaluate="NaN === NaN"></span><br>
<span data-evaluate="parseInt('A') === NaN"></span><br>
<span data-evaluate="parseInt('1') === NaN"></span><br>
<span data-evaluate="parseInt('B') === parseInt('B')"></span>
If you usually perform arithmetic calculations in your code, it is possible for NaN to appear naturally, whether it is conversion with type-to-type conversion (string for int, for example), or the sum with undefineds .
What is the concept, the mathematics behind this anomaly, and what makes NaN so confusing that it prevents a simple NaN === NaN from returning a false value although humanly speaking it should return true?