explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

quick FYI: Number & int

3 Comments

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…

Advertisements

3 thoughts on “quick FYI: Number & int

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

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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s