Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional JavaScript for Web Developers 3rd edition
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers, 3rd Edition by Nicholas C Zakas; ISBN: 978-1-1180-2669-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers 3rd edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 8th, 2017, 03:53 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2017
Location: Beijing, China
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post Number Conversions

On page 39, when it comes to transform Object into Number, the book said:" When applied to objects, the valuesOf() method is called and the returned value is converted based on the previously described rules. If that conversion results in NaN, the toString() method is called and the rules for converting strings are applied." However, I found if I write code as follow:
var obj = {
valueOf: function() {
return NaN;
},
toString: function() {
return -1;
}
}
document.write(Number(obj)); // NaN
If I comment out valueOf() method, then the result will be -1. That means when applied Number() to objects, the valueOf() method is called and the returned value is converted based on the previously described rules. If that conversion results in NaN, then returns NaN, but not calls toString() method. If there is no valueOf() method, then the toString() method is called.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL conversions - chapter 7 gorillapoop BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 February 15th, 2011 10:02 AM
Number conversions - has an omission P35 JGFMK BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 3 November 1st, 2010 06:11 PM
C# - Decimal to Single type Conversions ubayeed C# 1 December 22nd, 2004 07:48 PM
Type Conversions nikotromus Access VBA 2 October 7th, 2004 05:30 PM
Time conversions from 24hr to am/pm Blaise Classic ASP Basics 2 July 14th, 2003 09:38 PM



All times are GMT -4. The time now is 10:45 PM.


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