Learn JavaScript for Web Development

JavaScript is most versatile languages to code applications for the browser, desktop, phone or tablet. Write program for client browser or web server. Build interactive web site with JavaScript.

JavaScript - Number Object

The JavaScript number object enables you to represent a numeric value. It may be integer or floating-point. JavaScript number object follows IEEE standard to represent the floating-point numbers.

By the help of Number() constructor, you can create number object in JavaScript. For example:

var n=new Number(value);

If value can't be converted to number, it returns NaN(Not a Number) that can be checked by isNaN() method.

You can direct assign a number to a variable also. For example:

See this example:

var x=102;//integer value
var y=102.7;//floating point value
var z=13e4;//exponent value, output: 130000
var n=new Number(16);//integer value by number object


102 102.7 130000 16

JavaScript Number Constants

Let's see the list of JavaScript number constants with description.

MIN_VALUEreturns the largest minimum value.
MAX_VALUEreturns the largest maximum value.
POSITIVE_INFINITYreturns positive infinity, overflow value.
NEGATIVE_INFINITYreturns negative infinity, overflow value.
NaNrepresents "Not a Number" value.

JavaScript Number Methods

Let's see the list of JavaScript number methods with description.

toExponential(x)displays exponential value.
toFixed(x)limits the number of digits after decimal value.
toPrecision(x)formats the number with given number of digits.
toString()converts number into string.
valueOf()coverts other type of value into number.