Search within TutorialsPark

Javascript Number Object


Learn to use various properties and methods of Number Object.


Javascript Number Object: Introduction

The JavaScript Number Object is a reference for numeric values. A Number object is created using the Number constructor and then pass number as values.

The method toString() is used to return the number as a string, the method accepts a single argument to denote the radix of the number.

Example: Javascript : Number Object.

Give it a TRY! » Note: Radix or base specifies the numeral system used to represent numbers.


Javascript String Object : toFixed() Methods

The String object method toFixed() is used to return a string representation of a number with specified length of decimal points. Eg: an argument of 4 denotes 4 decimal digits

If the number has more than the specified no of decimal points, the number is rounded to the nearest decimal place.

Example: JavaScript String Object : toFixed() Method

Give it a TRY! » Note: The method toFixed() can be used to round off numbers as well.


Javascript Number Object: toExponential() Method

The Number object method toExponential() is used to return a string with the numbers represented in exponential notation(e-notation).

Example: JavaScript Number Object : toExponential() Method

Give it a TRY! » Note: The parameter must be between 0-20 always..


Javascript Number Object: toPrecision() Methods

The Number Object method toPrecision() is used to either return the fixed or the exponential representation of the number. It accepts an argument to specify the number of digits to be displayed.

Example: JavaScript Number Object : toPrecision()

Give it a TRY! » Note:The toPrecison() method determines what method is to be used, either toFixed() or toExponential().


Javascript Number Object: typeof and instanceof Operators

To know the type of numbers, i.e a primitive number or a reference number, the operators typeof or instanceof are used.

Using a typeof operator on primitive numbers returns a "number" , whereas a Number object returns object.

Example: JavaScript Number Object : typeof and instanceof

Give it a TRY! » Note:The instanceof operator is used to identify if the operand is an Object.


Javascript Number Object: Using Number Constants

The Number object has constants like MAX_VALUE, MIN_VALUE, NEGATIVE_INFINITY , POSITIVE_INFINITY and NaN

The MAX_VALUE and MIN_VALUE specifies the largest and the smallest representable number repectively

NEGATIVE_INFINITY , POSITIVE_INFINITY values are returned when the result of some mathematical operation overflows the min and max limits.

Example: JavaScript Number Object : Using Number Constants

Give it a TRY! » Note:The NaN value is returned when the result of mathematical operation is not a numbers.