quick FYI: Number & int
Preface: This may be common knowledge and have several dozen posts on it, but since I found this out on my own, I figure I would post on it.
Now I am not what you call an ActionScript know-it-all. In fact, I learn something nearly everyday about AS3 and Flex. That’s why I love my job. So I ran into an issue where I was using isNaN expecting to get true. Various values were getting passed in but I wasn’t getting consistent results. Why?
Well part of that was that I was passing int(s) as values. I hadn’t initialized the var to anything. I just said var i:int; much like we might define var n:Number; and its initialized value would be the numerical equivalent to null which is NaN.
Little to my knowledge this was occuring:
var n:Number;
trace(isNaN(n)); //true, because the default value of a Number is NaN
var i:int;
trace(isNaN(i)); //false, because int defaults to 0, not NaN
Cool tip? I’d like to think so. Anywho…
wishlist
If my memory serves me correctly, and int cannot hold NaN at all. It will always convert non-numeric values to zero.