English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The JavaScript Number object acts as a wrapper for primitive numeric values.
The Number object can be used to handle numbers.
JavaScript has only one numeric data type and cannot distinguish between integers and floating-point values.
Numbers can have or not have decimals:
var a = 3.14; // Numbers with decimals var b = 12; // Numbers without decimals
Scientific notation can be used to write very large or very small numbers:
var a = 1e5; // 100000 var b = 1e-1; // 0.1 var c = 1.23e9; // 1230000000
You can find ourIn the JavaScript Number tutorialLearn more about Numbers.
The following table lists the properties of the Number object:
Properties | Description |
---|---|
constructor | Returns a reference to the Number function used to create objects |
MAX_VALUE | Returns the largest number in JavaScript |
MIN_VALUE | Returns the smallest number in JavaScript |
MAX_SAFE_INTEGER | Returns the largest safe integer in JavaScript (2 53-1) |
MIN_SAFE_INTEGER | Returns the smallest safe integer in JavaScript (-2 53 - 1) |
NaN | Represents the 'Not-a-Number' value |
NEGATIVE_INFINITY | Represents negative infinity (returned when overflow occurs) |
POSITIVE_INFINITY | Represents positive infinity (returned when overflow occurs) |
prototype | Allows you to add properties and methods to the object |
The following table lists the methods of the Number object:
Method | Description |
---|---|
isFinite() | Check if the passed value is a finite number |
isInteger() | Check if the passed value is an integer |
isNaN() | Check if the passed value isNaNand is of type Number |
isSafeInteger() | Check if the value is a safe integer |
toExponential() | Convert a number to exponential notation |
toFixed() | Format a number using fixed-point notation |
toPrecision() | Return a string representing the number with a specified precision |
toString() | Convert a number to a string |
valueOf() | Return the original value of the Number object |
Note:All numeric methods return a new value, but they do not change the value of the original variable.