Javascript Number Properties
JavaScript's Number
data type has a number of built-in properties that allow you to access and manipulate numeric values.
Here are some of the most commonly used Number properties in JavaScript:
Number.MAX_VALUE
: Returns the maximum possible value for a number in JavaScript (1.7976931348623157e+308).Number.MIN_VALUE
: Returns the smallest possible value for a number in JavaScript (5e-324).Number.NaN
: Represents a value that is not a number.Number.NEGATIVE_INFINITY
: Represents negative infinity (-∞).Number.POSITIVE_INFINITY
: Represents positive infinity (+∞).Number.EPSILON
: Represents the difference between 1 and the smallest representable number greater than 1 (2.220446049250313e-16).Number.MAX_SAFE_INTEGER
: Represents the maximum safe integer in JavaScript (2^53 - 1).Number.MIN_SAFE_INTEGER
: Represents the minimum safe integer in JavaScript (-2^53 + 1).
Example of using Number properties in JavaScript code:
console.log(Number.MAX_VALUE); // Output: 1.7976931348623157e+308
console.log(Number.MIN_VALUE); // Output: 5e-324
console.log(Number.NaN); // Output: NaN
console.log(Number.NEGATIVE_INFINITY); // Output: -Infinity
console.log(Number.POSITIVE_INFINITY); // Output: Infinity
console.log(Number.EPSILON); // Output: 2.220446049250313e-16
console.log(Number.MAX_SAFE_INTEGER); // Output: 9007199254740991
console.log(Number.MIN_SAFE_INTEGER); // Output: -9007199254740991
info
NaN
is not equal to any value, including itself. You can use the isNaN()
function to check if a value is NaN
.
note
Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER
are the largest/smallest integers that can be safely represented in JavaScript without precision loss.
For larger integers, use BigInt
library.