JavaScript Number() function
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





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 »
JavaScript Global Functions