explorers’ club


quick FYI: Number & int
Friday, June 22, 2007, 9:55 pm
Filed under: actionScript

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…


3 Comments so far
Leave a comment

If my memory serves me correctly, and int cannot hold NaN at all. It will always convert non-numeric values to zero.

Comment by Josh

[...] and FLEX quick FYI: Number & int jwopitz wrote: Now I am not what you call an ActionScript know-it-all. In fact, I learn something nearly everyday [...]

Pingback by AS# and FLEX quick FYI: Number & int « Flash Enabled - Get Ready With Flash…

[...] quick FYI: Number & int « jwopitz – flex/flash exploration [...]

Pingback by Code Sweat Blog » Blog Archive » Some Flex 2 Related Links (pt. two)




Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>