The JavaScript number object allows for the representation of a numeric value, which can be either an integer or a floating-point number. It adheres to the IEEE standard for encoding floating-point numbers.
Utilizing the Number constructor, you are able to instantiate a number object in JavaScript. For instance:
var n=new Number(value);
If a value is unable to be transformed into a number, it yields NaN (Not a Number), which can be verified using the isNaN function.
You have the ability to directly assign a value to a variable as well. For instance:
var x=102;//integer value
var y=102.7;//floating point value
var z=13e4;//exponent value, output: 130000
var n=new Number(16);//integer value by number object
Output:
102 102.7 130000 16
JavaScript Number Constants
Let’s examine the compilation of JavaScript numeric constants along with their explanations.
| Constant | Description |
|---|---|
| MIN_VALUE | returns the largest minimum value. |
| MAX_VALUE | returns the largest maximum value. |
| POSITIVE_INFINITY | returns positive infinity, overflow value. |
| NEGATIVE_INFINITY | returns negative infinity, overflow value. |
NaN |
represents "Not a Number" value. |
JavaScript Number Methods
Here is a compilation of JavaScript number methods along with their respective descriptions.
| Methods | Description |
|---|---|
| isFinite() | It determines whether the given value is a finite number. |
| isInteger() | It determines whether the given value is an integer. |
| parseFloat() | It converts the given string into a floating point number. |
| parseInt() | It converts the given string into an integer number. |
| toExponential() | It returns the string that represents exponential notation of the given number. |
| toFixed() | It returns the string that represents a number with exact digits after a decimal point. |
| toPrecision() | It returns the string representing a number of specified precision. |
| toString() | It returns the given number in the form of string. |