Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing parseInt to NaN in Actionscript 3

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)
}
like image 612
Luke Avatar asked Nov 28 '22 18:11

Luke


2 Answers

Compare with isNaN() function.

like image 61
alxx Avatar answered Dec 09 '22 10:12

alxx


Use isNaN() global function

if(isNaN(parseInt("test")))
{
   // do something 
}
like image 22
Amarghosh Avatar answered Dec 09 '22 11:12

Amarghosh