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

JavaScript Number Object

The JavaScript Number object acts as a wrapper for primitive numeric values.

Number object

The Number object can be used to handle numbers.

JavaScript has only one numeric data type and cannot distinguish between integers and floating-point values.

Numbers can have or not have decimals:

var a = 3.14;     // Numbers with decimals
var b = 12;       // Numbers without decimals

Scientific notation can be used to write very large or very small numbers:

var a = 1e5;      // 100000
var b = 1e-1;     // 0.1
var c = 1.23e9;   // 1230000000

You can find ourIn the JavaScript Number tutorialLearn more about Numbers.

Number object properties

The following table lists the properties of the Number object:

PropertiesDescription
constructorReturns a reference to the Number function used to create objects
MAX_VALUEReturns the largest number in JavaScript
MIN_VALUEReturns the smallest number in JavaScript
MAX_SAFE_INTEGERReturns the largest safe integer in JavaScript (2 53-1)
MIN_SAFE_INTEGERReturns the smallest safe integer in JavaScript (-2 53 - 1)
NaNRepresents the 'Not-a-Number' value
NEGATIVE_INFINITYRepresents negative infinity (returned when overflow occurs)
POSITIVE_INFINITYRepresents positive infinity (returned when overflow occurs)
prototypeAllows you to add properties and methods to the object

Number Object Methods

The following table lists the methods of the Number object:

MethodDescription
isFinite()Check if the passed value is a finite number
isInteger()Check if the passed value is an integer
isNaN()Check if the passed value isNaNand is of type Number
isSafeInteger()Check if the value is a safe integer
toExponential()Convert a number to exponential notation
toFixed()Format a number using fixed-point notation
toPrecision()Return a string representing the number with a specified precision
toString()Convert a number to a string
valueOf()Return the original value of the Number object

Note:All numeric methods return a new value, but they do not change the value of the original variable.