Number object constructorS2C Home « Globals « Number

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
valueA numerical value.
  • Passed values that can't be converted return NaN.

Class Properties


Class Property Description
MAX_VALUEMaximum positive number value that can be represented in JavaScript.
MIN_VALUEMinimum positive number value that can be represented in JavaScript.
NaNJavaScript Not-A-Number value.
NEGATIVE_INFINITYJavaScript value representing negative infinity.
POSITIVE_INFINITYJavaScript value representing positive infinity.
prototypeEnables property assignment to objects of type Number.

Instance Properties


Instance Property Description
constructorReturns a reference to the Number function that created the prototype.

Class Methods

None.

Instance Methods

By using methods of the Number object we can also access elements of numbers, manipulate numbers after creation and even create new numbers from existing numbers.

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);

Press the button below to action the above code:


Related Tutorials

JavaScript Advanced Tutorials - Lesson 3 - Number

go to home page Homepage go to top of page Top