--- 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 ---
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')}} |
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}} |