Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Number() function

JavaScript Number() function

Function Reference JavaScript Global Functions


Definition and Usage

The Number() function converts the value of an object to a number.

If the value of an object cannot be converted to a number, the Number() function returns NaN.

Syntax

Number(object)

Parameters Description
object Optional. A JavaScript object. If no argument is provided, 0 is returned.

Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the Number() function


Tips and Notes

**Note:** If the argument is a Date object, Number() returns the number of milliseconds from January 1, 1970 to the present.


Example

Example

Convert different objects to numbers:

The output of the above example is:

Try it »


Function Reference JavaScript Global Functions