--- title: Number.prototype.valueOf() slug: Web/JavaScript/Reference/Global_Objects/Number/valueOf tags: - JavaScript - Method - Number - valueOf() translation_of: Web/JavaScript/Reference/Global_Objects/Number/valueOf ---
{{JSRef("Global_Objects", "Number")}}

概述

valueOf() 方法返回一个被 {{jsxref("Global_Objects/Number", "Number")}} 对象包装的原始值。

语法

numObj.valueOf()

返回值

表示指定 {{jsxref("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  
{{SpecName('ES5.1', '#sec-15.7.4.4', 'Number.prototype.valueOf')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-number.prototype.valueof', 'Number.prototype.valueOf')}} {{Spec2('ES6')}}  

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

相关链接