Number

Introduction

The Number object represents a number.

constructor

The constructor method returns the function that created the Number object's prototype. The following is the syntax for the constructor method.

obj.constructor;

Example

The following is the code for the constructor method.

var obj = new Number(123.456); document.write(obj.constructor);

On running the above code, the following output is obtained.

MAX_VALUE

The MAX_VALUE method returns the largest number possible in JavaScript. The following is the syntax for the MAX_VALUE method.

Math.MAX_VALUE;

Example

The following is the code for the MAX_VALUE method.

document.write(Math.MAX_VALUE);

On running the above code, the following output is obtained.

MIN_VALUE

The MIN_VALUE method returns the smallest number possible in JavaScript. The following is the syntax for the MIN_VALUE method.

Math.MIN_VALUE;

Example

The following is the code for the MIN_VALUE method.

document.write(Math.MIN_VALUE);

On running the above code, the following output is obtained.

NEGATIVE_INFINITY

The NEGATIVE_INFINITY method Represents negative infinity (returned on overflow). The following is the syntax for the NEGATIVE_INFINITY method.

Math.NEGATIVE_INFINITY;

Example

The following is the code for the NEGATIVE_INFINITY method.

document.write(Math.NEGATIVE_INFINITY);

On running the above code, the following output is obtained.

POSITIVE_INFINITY

The POSITIVE_INFINITY method Represents infinity (returned on overflow). The following is the syntax for the POSITIVE_INFINITY method.

Math.POSITIVE_INFINITY;

Example

The following is the code for the POSITIVE_INFINITY method.

document.write(Math.POSITIVE_INFINITY);

On running the above code, the following output is obtained.

prototype

The prototype method allows properties and methods to be added to an object. The following is the syntax for the prototype method.

obj.prototype;

Example

The following is the code for the prototype method.

var obj = new Number(); document.write(obj.prototype);

On running the above code, the following output is obtained.

toExponential(x)

The toExponential(x) method converts a number into an exponential notation. The following is the syntax for the toExponential(x) method.

obj.toExponential(x);

Example

The following is the code for the toExponential(x) method.

var obj = new Number(123.456); document.write(obj.toExponential(2));

On running the above code, the following output is obtained.

toFixed(x)

The toFixed(x) method formats a number with x numbers of digits after the decimal point. The following is the syntax for the toFixed(x) method.

obj.toFixed(x);

Example

The following is the code for the toFixed(x) method.

var obj = new Number(123.456); document.write(obj.toFixed(2));

On running the above code, the following output is obtained.

toPrecision(x)

The toPrecision(x) method formats a number to x length. The following is the syntax for the toPrecision(x) method.

obj.toPrecision(x);

Example

The following is the code for the toPrecision(x) method.

var obj = new Number(123.456); document.write(obj.toPrecision(2));

On running the above code, the following output is obtained.

toString()

The toString() method converts a Number object to a string. The following is the syntax for the toString() method.

obj.toString();

Example

The following is the code for the toString() method.

var obj = new Number(123.456); document.write(obj.toString());

On running the above code, the following output is obtained.

valueOf()

The valueOf() method returns the primitive value of a Number object. The following is the syntax for the valueOf() method.

obj.valueOf();

Example

The following is the code for the valueOf() method.

var obj = new Number(123.456); document.write(obj.valueOf());

On running the above code, the following output is obtained.