p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning HTML, XHTML, CSS, and JavaScript (http://p2p.wrox.com/forumdisplay.php?f=541)
-   -   NaN... is it in the book? (http://p2p.wrox.com/showthread.php?t=80214)

rebman July 21st, 2010 08:45 PM

NaN... is it in the book?
 
Hi,

I've looked as best I can to find something about NaN in the book, but was unsuccessful. Did I just miss it? Is so, where is it discussed in the book?

Thanks,
Paul

Old Pedant July 22nd, 2010 06:27 PM

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.

rebman July 22nd, 2010 08:28 PM

Thanks for your reply and explanation. I did find information on it elsewhere. (A simple google search got all the information I needed.)

The reason I asked is that I just bought the book and it was the first thing I tried to look up in the book and couldn't find it. That's happened to me before with books -- I try to find something apparently simple in the book and it's not there. Rather disappointing.

Old Pedant July 22nd, 2010 09:00 PM

You piqued my curiosity. I downloaded all the code for the book and did a scan for "NaN" (case sensitive).

The ONLY place it appears is in code from Chapter 12. And it looks to me like in there, even, the only place it appears is in the various libraries. Such as jquery, MochiKit, scriptaculous, etc.

I agree, this is a little disappointing. I would have expected a book that discusses HTML and JavaScript to have, for example, some basic examples of form validation, including of course the use of parseFloat() and/or parseInt().

Okay, so do a search for parseFloat. Same results.

Even a search for the word function shows very few results outside of chapter 12, and not a one of those that seems to do validation of numeric input. Same with searches for match( and test( which would be used for validation via regular expressions.

Somehow, it doesn't look like this is the book to learn JavaScript from. Might be fine for HTML and CSS, but clearly it doesn't address JavaScript development, at all. Looks like all it does is show you how to use some of the various libraries. Yes?

Okay, finally looked at the Table of Contents. No, this is definitely not a book for learning JavaScript. A few fundamentals in a few pages, and that's all. Can't comment on the HTML and CSS, though the ToC looks like they are covered fairly well. Esp. in comparison to the JS coverage.

rebman July 22nd, 2010 09:25 PM

Thanks. You were much more thorough than I was. As you say, this book isn't much on JavaScript, but hopefully XHTML and CSS are better covered.

Paul


All times are GMT -4. The time now is 02:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.