Tales from the Evil Empire

Bertrand Le Roy's blog

News


Bertrand Le Roy


Add to Technorati Favorites Tales from the Evil Empire - Blogged

Blogs I read

My other stuff

Archives

NaN is a number

JavaScript, like .NET, has a special thing called NaN, which stands for Not a Number. It is useful to determine if parsing a string successfully returned a number or for some operation results. Well, guess what this evaluates to:

typeof(Number.NaN)

Yes, you guessed it from the title, it evaluates to "number".

Just thought you might find this funny (as I did).

Comments

Skinny Runt said:

dork :D
# June 29, 2006 6:05 PM

Bertrand Le Roy said:

I know :|

# June 29, 2006 6:07 PM

dave said:

that's hilarious :-/
# June 29, 2006 7:37 PM

Mukesh said:

Hi... Thanks for .... Can you give one more example of this in detail. Mukesh
# June 30, 2006 3:15 AM

Chris said:

It is wrong to be as amused as I am. And yet, I am. :)
# June 30, 2006 11:20 AM

ASP.NET Team Blogs said:

We already knew that JavaScript had some issues with semantics. Here's another funny one. Guess what

# August 2, 2006 7:38 PM

EricW said:

Not as silly as you think. NaN is a property of the Number object. It is intended to be uses in comparisons, not as a value (object or not) of its own. You can think of it as a special form of Number or as a special type within the Number object. Number is really a helper object, mainly to deal with conversions to strings. So if you keep in mind that NaN is intended to be used -- by javascript -- as a test value for the function IsNaN, it perfectly makes sence.
# August 3, 2006 3:44 AM

Bertrand Le Roy said:

Eric: sure, I was just pointing out that it's funny. Please notice that I didn't say it was stupid ;) but I wouldn't go so far as saying it "perfectly makes sense".

# August 3, 2006 1:58 PM

NoBuddy said:

NaN stands for Not-A-Number, but internally you can also assume it to be infinity. So 0/0 should churn out NaN

# September 4, 2009 3:50 AM

Bertrand Le Roy said:

@NoBuddy: not exactly true. JavaScript actually has positive and negative infinities, which you can get by doing 1/0 or -1/0. 0/0 does give you NaN though because it can't determine the sign, but isNaN(1/0) returns false. So infinity is a number as far as JavaScript is concerned...

# September 4, 2009 11:34 AM

Shawn T said:

This may also make sense when considered from the standpoint of the floating-point standard.

# October 27, 2010 7:01 PM