In JavaScript, there are some useful properties associated with the number
data type that can be accessed using the Number
object.
Number.MAX_VALUE
Number.MAX_VALUE
is the largest positive number that can be represented with the number
data type in JavaScript. It has a value of approximately 1.79 × 10^308.
console.log(Number.MAX_VALUE); // Output: 1.7976931348623157e+308
Number.MIN_VALUE
Number.MIN_VALUE
is the smallest positive number that can be represented with the number
data type in JavaScript. It has a value of approximately 5 × 10^-324.
console.log(Number.MIN_VALUE); // Output: 5e-324
Number.POSITIVE_INFINITY
Number.POSITIVE_INFINITY
represents positive infinity, which is a value that is greater than any other number. This value is returned when a number is too large to be represented with the number
data type.
console.log(Number.POSITIVE_INFINITY); // Output: Infinity
Number.NEGATIVE_INFINITY
Number.NEGATIVE_INFINITY
represents negative infinity, which is a value that is less than any other number. This value is returned when a number is too small (i.e. more negative) to be represented with the number
data type.
console.log(Number.NEGATIVE_INFINITY); // Output: -Infinity
Number.NaN
Number.NaN
represents Not-a-Number, which is a value that indicates an undefined or unrepresentable mathematical value. This value is returned when a mathematical operation cannot be performed, such as dividing zero by zero.
console.log(Number.NaN); // Output: NaN
These properties are useful for working with numbers in JavaScript, especially when dealing with large or small values.