Comparing parseInt to NaN in Actionscript 3

Luke picture Luke · Oct 18, 2010 · Viewed 10.1k times · Source

The AS3 documentation states that if you pass in a string to parseInt that is not a number it will return NaN. However, when I try to compare to NaN the compiler gives me the following error:

Warning: 1098: Illogical comparison with NaN. This statement always evaluates to false.

The statement is actually true. Comparing to NaN will always return false. How can I compare to NaN to detect if what was parsed was NaN?

if( parseInt("test") == NaN )
{
   // do something (never gets here)
}

Answer

alxx picture alxx · Oct 18, 2010

Compare with isNaN() function.