View Single Post
  #2 (permalink)  
Old July 22nd, 2010, 06:27 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

No idea if it's in the book, but if you just want to know what it means:

NaN is actually part of the IEEE specification for floating point numbers. It represents a bit pattern that is impossible in well-formed floating point number.

JavaScript utilizes and extends this meaning and capability: Any time you try to convert a string (or other object type) to a number and the conversion fails (because the string doesn't represent a legal number), the result is marked as NaN.

So, for example:
Code:
var count = parseFloat( "aardvarks" );
will assign the value NaN to the variable count.

JavaScript also provides a convenient way to test if a variable contains the NaN value:
Code:
if ( isNaN(count) ) alert("count is NaN");
And that's about all NaN is used for: An indication that a conversion from string to number failed. It *can* mean a few other (very obscure) things, but I doubt you'll ever encounter them.
Reply With Quote