Not A Number (NaN) –
NaN property stands for “Not A Number” value. This indicates that a value is not a legal number. So NaN can be equal to NaN
In order to check number is a legal number use the isNaN() global function.
NaN property syntax –
isNaN() Function Syntax –
For more detail about Not a Number NaN click here.
First, declare a variable valueOne using the let keyword and assign NaN value to it.
let valueOne = NaN;
First, declare another variable valueTwo using the let keyword and assign NaN value to it.
let valueTwo = NaN;
Now, comparing an valueOne and valueTwo together with equal and typed equal.
console.log(valueOne == valueTwo);
console.log(valueOne === valueTwo);
Any idea, what should be the output of above console log statement.
Now, you know the answer is false, false. But why as they both looks same. Let me explain.
InShort – According to IEEE 754 specifications any operation performed on NaN values should yield a false value or should raise an error.
So, NaN gives false output when compare with NaN. If NaN not equal to NaN.
Then typed equal also gives the false output.
console.log(valueOne == valueTwo); // false
console.log(valueOne === valueTwo); // false
At last, That’s why we get an answer “false, false“.
Let me know in the comment section, what you think about it.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
- JS Quiz – can array from method be like a map method
- JS Quiz – compare the self value with data type
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.