English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Number() Function

 JavaScript Global Properties/Function

The function of the Number() is to convert the given object parameter to a number.

Returns NaN if the value cannot be converted to a number.

If the parameter is a Date object, the Number() function returns the milliseconds since UTC 1970 years1Month1Milliseconds since the start of the day at midnight.

Syntax:

Number(object)
Number(true); // 1
Number(false);// 0
Number('100');// 100
Number('2 + 6);  // NaN
Number(new Date());
Test and see‹/›

Browser Compatibility

All browsers fully support the Number() function:

Function
Number()IsIsIsIsIs

Parameter Value

ParameterDescription
objectA JavaScript object. Returns 0 if no arguments are provided.

Technical Details

Return value:Returns the numeric value corresponding to different object values:
  • Returns NaN if the value cannot be converted to a legal number.

  • Returns 0 if no arguments are provided.

JavaScript Version:ECMAScript 1

 JavaScript Global Properties/Function