Lets you work with numeric values. The Number object is an object wrapper for primitive numeric values.
Core object
Created by
The Number constructor:
new Number( value )
Parameters
Parameter | Description |
---|---|
value | The numeric value of the object being created. |
Description
The primary uses for the Number object are:
To access its constant properties, which represent the largest and smallest representable numbers, positive and negative infinity, and the Not-a-Number value.
To create numeric objects that you can add properties to. Most likely, you will rarely need to create a Number object.
The properties of Number are properties of the class itself, not of individual Number objects.
Property Summary
Property | Description |
---|---|
constructor | Specifies the function that creates an object's prototype. |
MAX_VALUE | The largest representable number. |
MIN_VALUE | The smallest representable number. |
NaN | Special "not a number" value. |
NEGATIVE_INFINITY | Special value representing negative infinity; returned on overflow. |
POSITIVE_INFINITY | Special value representing infinity; returned on overflow. |
prototype | Allows the addition of properties to a Number object. |
Method Summary
Method | Description |
---|---|
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. |
In addition, this object inherits the Object.watch and Object.unwatch methods from Object.
Examples
Example 1. The following example uses the Number object's properties to assign values to several numeric variables:
biggestNum = Number.MAX_VALUE;
smallestNum = Number.MIN_VALUE;
infiniteNum = Number.POSITIVE_INFINITY;
negInfiniteNum = Number.NEGATIVE_INFINITY;
notANum = Number.NaN;
Example 2. The following example creates a Number object, myNum, then adds a description property to all Number objects. Then a value is assigned to the myNum object's description property.
myNum = new Number( 65 )
Number.prototype.description = null;
myNum.description = "wind speed";