JavaScript Number valueOf() method

Definition and usage

valueOf() The method returns the original value of the number.

Example

Get the original value of the number:

let num = 15;
let n = num.valueOf();

Try it yourself

Syntax

number.valueOf()

Parameter

No parameters.

Return value

Type Description
Number The original value of the number.

Technical details

Return value

number The original value. There is almost no need to explicitly call this method.

Throw

Exception Description
TypeError An exception is thrown when the object called by the method is not Number.

browser supports

valueOf() 是 ECMAScript1 (ES1) 特性。

所有浏览器都完全支持 ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
支持 支持 支持 支持 支持 支持