JavaScript treats and represent all the numbers as floating-point numbers. It does not have any different data types defined for a number. The calculations in javascript are very tricky as it automatically converts the types and gives the result, it can sometimes lead to wrong outputs.
The JavaScript number object enables you to represent a numeric value. It may be integer or floating-point. It follows IEEE standard to represent the floating-point numbers. A number object can be created by the help of Number() constructor.
JavaScript supports both integer and floating-point numbers that can be represented in decimal, hexadecimal or octal notation. Unlike other languages, JavaScript does not treat integer and floating-point numbers differently.
All numbers in JavaScript are represented as floating-point numbers. If the value can't be converted to number, it returns NaN
(Not a Number) that can be checked by isNaN() method.
Property | Description |
---|---|
var x=100; | Integer Value |
var x=105.5; | Floating point number |
var x=13e4; | Exponent value, output: 130000 |
var n=new Number(16); | Integer value by number object |
Property | Description |
---|---|
MIN_VALUE | The smallest positive representable number - that is, the positive number closest to zero (without actually being zero). |
MAX_VALUE | The largest positive representable number |
POSITIVE_INFINITY | Represents positive infinity, returned on overflow. |
NEGATIVE_INFINITY | Represents negative infinity, returned on overflow. |
Nan | Represents "Not a Number" value. |
The MIN_VALUE
property gives the minimum positive value closest to zero. Numbers smaller than this are converted to zero.
The MAX_VALUE
property gives the maximum possible positive value in Javascript. Numbers larger than MAX_VALUE are treated as infinity.
The POSITIVE_INFINITY
property can be considered as a number which is greater than any other number.
The NEGATIVE_INFINITY
property can be considered as a number which is lower than any other number.
JavaScript Infinity represents a number too big for JavaScript to handle.
JavaScript has special keyword Infinity
and -Infinity
that represent positive and negative infinity
respectively.
For example, dividing by 0 returns Infinity, as demonstrated below:
Follow Us: