Object Number in JavaScript

The Number object represents the date in the form of a numeric value, or an integer or floating-point number. Generally, you don't need to worry about Number objects because the browser automatically converts number literals to illustrate the number classes.

The Number object represents the date in the form of a numeric value, or an integer or floating-point number. Generally, you don't need to worry about Number objects because the browser automatically converts number literals to illustrate the number classes.

Syntax

Syntax to create a Number object as follows:

 var val = new Number ( number ); 

In the position of number, if you provide any non-numeric value, then the parameter cannot be converted to a number, it returns NaN (short for Not-a-Number).

The properties of Number

Below is a list of its attributes and descriptions.

Properties Description

MAX_VALUE

The maximum possible value of some in JavaScript can be up to 1.7976931348623157E + 308

MIN_VALUE

The smallest possible value of some in JavaScript can reach 5E-324

NaN

Equivalent to value that is not a number

NEGATIVE_INFINITY

A value less than MIN_VALUE

POSITIVE_INFINITY

A value greater than MAX_VALUE

prototype

Static attribute of Number object. Use the prototype property to assign new properties and methods to the Number object in the current document

constructor

Returns the function that creates the illustration of this object. By default, it is the Number object

The methods of Number

The Number object contains only the default methods that are part of each object definition.

Method Description

toExponential ()

Make some impressions in exponential form, even if this number is in a range in which JavaScript often uses standard notation.

toFixed ()

A number format with a specific number of digits to the right of the decimal part.

toLocaleString ()

Returns a string value version of the current number in a format that can be varied according to the browser internal setting.

toPrecision ()

Define how many digits (including the digits on the right and left of the decimal part) to display a number.

toString ()

Returns the string representation of the numeric value.

valueOf ()

Returns the value of the number.

According to Tutorialspoint

Previous article: Objects in JavaScript

Next lesson: Boolean object in JavaScript

3.5 ★ | 2 Vote