JS Number Object

Number object

The Number object is a wrapper object for the original numeric value.

Number is created as new Number().


var num = new Number(value);

Note: If a parameter value cannot be converted to a number, NaN (non-numeric value) is returned.

Number object tutorial, please refer to JavaScript Number object tutorial .

Number object properties

constructorReturns a reference to the Number function that created this object.
MAX_VALUEThe largest number that can be represented.
MIN_VALUEThe smallest number that can be represented.
NEGATIVE_INFINITYNegative infinity, which is returned when overflowing.
NaNNon-numeric values.
POSITIVE_INFINITYPositive infinity, returns the value when overflowing.
prototypeAllows you to add properties and methods to objects.

Number object methods

isFiniteDetects whether the specified parameter is infinity.
toExponential(x)Converts the value of the object to exponential notation.
toFixed(x)Converts a number to a string with the result of a number of digits specified after the decimal point.
toPrecision(x)Formats numbers to the specified length.
toString()Converts a number to a string, using the specified cardinality.
valueOf()Returns the base numeric value of a Number object.

ES6 Added Number property

ES 6 adds the following three properties for the Number object:

  • EPSILON: Represents the difference between 1 and the smallest Number that is closer to 1 and greater than 1

  • MIN_SAFE_INTEGER: Represents the smallest secure integer type number in JavaScript ( - (253 - 1)).

  • MAX_SAFE_INTEGER: Represents the largest safe integer in JavaScript (253 - 1).


var x = Number.EPSILON;
var y = Number.MIN_SAFE_INTEGER;
var z = Number.MAX_SAFE_INTEGER;

 Try It! 

ES6 adds a Number method

ES 6 adds the following two methods for the Number object:

  • Number.isInteger(): Used to determine whether a given argument is an integer.

  • Number.isSafeInteger(): Determines whether the value of the parameter passed in is a "safe integer".

Number.isInteger() returns true when the argument is an integer.


Number.isInteger(10);        // return true
Number.isInteger(10.5);      // return false

Try It! 

Number.isSafeInteger() determines whether the value of the parameter passed in is a "safe integer".

The safe integer range is an integer between , containing -(253 - 1) till 253 - 1, includes -(253 - 1) and 253 - 1 .


Number.isSafeInteger(10);    // return true
Number.isSafeInteger(12345678901234567890);  // return false

Try It!