Number.prototype.valueOf()

概述

valueOf() 方法返回一个被 Number 对象包装的原始值。

语法

numObj.valueOf()

返回值

表示指定 Number 对象的原始值的数字

描述

该方法通常是由 JavaScript 引擎在内部隐式调用的,而不是由用户在代码中显式调用的。

示例

var numObj = new Number(10);
console.log(typeof numObj); // object

var num = numObj.valueOf();
console.log(num);           // 10
console.log(typeof num);    // number

规范

规范名称 规范状态 备注
ECMAScript 1st Edition. Standard  
ECMAScript 5.1 (ECMA-262)
Number.prototype.valueOf
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
Number.prototype.valueOf
Standard  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接