In JavaScript you create a number instance using the constructor Number
.
Description
Creates a wrapper object for use with numerical values.
- Can be used in a non-constructor context for type conversion.
Syntax
Signature |
Description |
var aNumber = new Number(value); | Creates a wrapper object for use with numerical values. |
Parameters
Parameter |
Description |
value | A numerical value.
- Passed values that can't be converted return
NaN .
|
Class Properties
Class Property |
Description |
MAX_VALUE | Maximum positive number value that can be represented in JavaScript. |
MIN_VALUE | Minimum positive number value that can be represented in JavaScript. |
NaN | JavaScript Not-A-Number value. |
NEGATIVE_INFINITY | JavaScript value representing negative infinity. |
POSITIVE_INFINITY | JavaScript value representing positive infinity. |
prototype | Enables property assignment to objects of type Number . |
Instance Properties
Instance Property |
Description |
constructor | Returns a reference to the Number function that created the prototype. |
Class Methods
None.
Instance Methods
Instance Method |
Description |
Getter (Accessor) MethodsThese methods DO NOT modify the Number object |
toExponential() | Returns a string representation of the number in exponential notation. |
toFixed() | Returns a string representation of the number in fixed-point notation. |
toLocaleString() | Returns a string representation of the number using locale specific notation. |
toPrecision() | Returns a string representation of the number to the specified precision in fixed-point or exponential notation. |
toString() | Returns a string representation of the numeric value. |
valueOf() | Returns the primitive value of the Number object. |
Setter (Mutator) MethodsThese methods DO modify the Number object |
None. |
Examples
// Create an array with some class properties.
var classProps = new Array(5);
classProps[0] = Number.MAX_VALUE;
classProps[1] = Number.MIN_VALUE;
classProps[2] = NaN;
classProps[3] = Number.NEGATIVE_INFINITY;
classProps[4] = Number.POSITIVE_INFINITY;
alert(classProps);
Related Tutorials
JavaScript Advanced Tutorials - Lesson 3 - Number