Not a Number: use the top-level function isNaN() : Number « Data Type « Flash / Flex / ActionScript






Not a Number: use the top-level function isNaN()

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
         var n:Number;
         trace(n); //NaN
         trace(isNaN(n)); //true
         trace(n == NaN); //false! That's why you use isNaN()
         n = Number("this won't convert into a number");
         trace(isNaN(n)); //true
         n = 10;
         trace(isNaN(n)); //false
    }
  }
}

        








Related examples in the same category

1.Use Number type variable in for loop
2.Read and write to a variable
3.Decimal Numbers
4.Casting to a Number: Number(stringValue)
5.Dealing with Infinite Values: Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY
6.Handling Minimum and Maximum Values: MAX_VALUE and MIN_VALUE
7.Minimum and Maximum Values for uint and int
8.Working with Number Instances
9.The default value for an unassigned variable of type Number is NaN