码迷,mamicode.com
首页 > 其他好文 > 详细

ToNumber

时间:2019-04-24 00:24:03      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:value   abs   bst   es5   neither   ret   rac   opera   nal   

true becomes 1 and false becomes 0. undefined becomes NaN, but (curiously) null becomes 0
Objects (and arrays) will first be converted to their primitive value equivalent, and the resulting value (if a primitive but not already a number) is coerced to a number according to the ToNumber rules just mentioned.

To convert to this primitive value equivalent, the ToPrimitive abstract operation (ES5 spec, section 9.1) will consult the value (using the internal DefaultValue operation -- ES5 spec, section 8.12.8) in question to see if it has a valueOf() method. If valueOf() is available and it returns a primitive value, that value is used for the coercion. If not, but toString() is available, it will provide the value for the coercion.

If neither operation can provide a primitive value, a TypeError is thrown.

ToNumber

标签:value   abs   bst   es5   neither   ret   rac   opera   nal   

原文地址:https://www.cnblogs.com/zlv2snote/p/10759818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!