Number in javascript is any number either it is integer or floating number, is always a double precision 64 bit number or double precision floating point numbers as IEEE 754 specification.
Number is a data type in javascript, which is used to store integer or floating numbers in a variable in a positive and negative range from 2 -1074 to 2 1023 × (2 – 2-52) as IEEE 754 specification. Numbers stored beyond this range does not produce accurate results.
Example
<script>
let a = 20;
let b = 40;
let c = a + b;
document.write(c);
</script>
Get smallest positive numeric value
<script>
document.write(Number.MIN_VALUE);
</script>
Number.MIN_VALUE is a static data property, returns smallest non-zero positive numeric value in javascript.
Get maximum positive numeric value
<script>
document.write(Number.MAX_VALUE);
</script>
Number.MAX_VALUE is a static data property in javascript, returns maximum non-zero positive numeric value.
Number min and max value range
Number.MIN_VALUE | 2-1074 or 5E-324 |
Number.MAX_VALUE | 21024 – 2971 |
Check given number is a safe integer
javascript provides a static method isSafeInteger() to check, a given integer number is in safe range or not.
<script>
let num = 40;
if (Number.isSafeInteger(num)) {
document.write(num);
}
</script>
NaN
Its full-form is Not A Number. javascript returns NaN, when a value or data is not number.
Check weather the value is number or not
javascript provides a method called isNaN(), which checks given number is a valid number or not.
<script>
let num = 40;
if(isNaN(num))
document.write(num);
</script>
Infinity
It is used to represent positive infinity. It is the highest numeric value available in javascript. crosses upper limit.
-Infinity
It represents negative infinity and the smallest numeric value available. crosses lower limit