JavaScript » Objects » Number

new Number(value)

The Number object is an object wrapper for primitive numeric values, allowing for their manipulation. To create a Number object use Number constructor above.


five = new Number(5)

This following example creates a Number object of the numeric value 5. The main reason for doing this is to be able to use the constant properties for the Number object, although you can create one in order to add properties to it. You can also convert any object to a number by using the Number function.



Syntax: object.constructor

This property specifies the function that created the object's prototype. See also the Object.constructor property.


Syntax: Number.MAX_VALUE

This property represents the largest value possible in JavaScript. It is a static property and hence always referred to as Number.MAX_VALUE, and has a value of approximately 1.79769e+308. Numbers larger than this are represented as infinity.


Syntax: Number.MIN_VALUE

This property represents the smallest positive number possible in JavaScript, and as a static property is always referred to as Number.MIN_VALUE. Its value is 5e-324, and any value smaller than that is converted to 0.


Syntax: Number.NaN

This read-only property represents the special value Not-a-Number, and is always unequal to any other number (including 0) and to NaN itself. As a static property, it is always referred to as Number.NaN.



This static, read-only property is a special value representing negative infinity, which is returned on overflow.


Syntax: object.prototype

This property represents the prototype for this object and allows you to add methods and properties of your own. See also the Function.prototype property.



Syntax: object.toExponential(fractionDigits)

This method returns a string containing the number in exponential form.


Syntax: object.toFixed(fractionDigits)

This method returns a string containing the number represented in fixed-point notation with fractionDigits following the decimal point.


Syntax: object.toString([radix])

This method returns a string representing the Number object, and is called by JavaScript whenever the code requires a string value. The optional 'radix' parameter is an integer between 2 and 36 which specifies the base to be used when representing numeric values. This method overrides the Object.toString method.


Syntax: object.valueOf()
The Number object also inherits the watch and unwatch methods from the Object object.

This method, which is usually called by Javascript behind the scenes, returns the primitive value of a Number object as a number data type. This method overrides the Object.valueOf method.

See Also: