I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true:
parseFloat(\'geoff\') == NaN;
parseFloat(\'ge
I wrote this answer to another question on StackOverflow where another checks when NaN == null but then it was marked as duplicate so I don't want to waste my job.
Look at Mozilla Developer Network about NaN.
Just use distance || 0 when you want to be sure you value is a proper number or isNaN() to check it.
The NaN (Not-a-Number) is a weirdo Global Object in javascript frequently returned when some mathematical operation failed.
You wanted to check if NaN == null which results false. Hovewer even NaN == NaN results with false.
A Simple way to find out if variable is NaN is an global function isNaN().
Another is x !== x which is only true when x is NaN. (thanks for remind to @raphael-schweikert)
Let's find out.
When you call NaN == false the result is false, same with NaN == true.
Somewhere in specifications JavaScript has an record with always false values, which includes:
NaN - Not-a-Number"" - empty stringfalse - a boolean falsenull - null objectundefined - undefined variables0 - numerical 0, including +0 and -0