Visit Mozilla.org

Core JavaScript 1.5 Guide:Predefined Core Objects:Number Object

From MDC


[edit] Number Object

The Number object has properties for numerical constants, such as maximum value, not-a-number, and infinity. You cannot change the values of these properties and you use them as follows:

biggestNum = Number.MAX_VALUE
smallestNum = Number.MIN_VALUE
infiniteNum = Number.POSITIVE_INFINITY
negInfiniteNum = Number.NEGATIVE_INFINITY
notANum = Number.NaN

You always refer to a property of the predefined Number object as shown above, and not as a property of a Number object you create yourself.

The following table summarizes the Number object's properties.

Property Description
MAX_VALUE The largest representable number
MIN_VALUE The smallest representable number
NaN Special "not a number" value
NEGATIVE_INFINITY Special negative infinite value; returned on overflow
POSITIVE_INFINITY Special positive infinite value; returned on overflow

Table 7.2: Properties of Number

The Number prototype provides methods for retrieving information from Number objects in various formats. The following table summarizes the methods of Number.prototype.

Method Description
toExponential Returns a string representing the number in exponential notation.
toFixed Returns a string representing the number in fixed-point notation.
toPrecision Returns a string representing the number to a specified precision in fixed-point notation.
toSource Returns an object literal representing the specified Number object; you can use this value to create a new object. Overrides the Object.toSource method.
toString Returns a string representing the specified object. Overrides the Object.toString method.
valueOf Returns the primitive value of the specified object. Overrides the Object.valueOf method.

Table 7.3: Methods of Number.prototype

« Previous Next »