Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 8th, 2017, 04: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.


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 11: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 08: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





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