Number Properties
In JavaScript, the Number
object provides several static properties that define important numerical constants and limits. These properties are accessed directly on Number
rather than on individual numbers.
Number.EPSILON
Represents the smallest difference between 1 and the next representable floating-point number greater than 1.
It is approximately 2.220446049250313e-16
.
console.log(Number.EPSILON); // 2.220446049250313e-16
Number.MAX_VALUE
The largest positive finite number representable in JavaScript, approximately 1.7976931348623157e+308
.
Numbers exceeding this become Infinity
.
console.log(Number.MAX_VALUE); // 1.7976931348623157e+308
Number.MIN_VALUE
The smallest positive number greater than 0, approximately 5e-324
.
console.log(Number.MIN_VALUE); // 5e-324
Number.MAX_SAFE_INTEGER
The largest integer that can be safely represented without losing precision: 9007199254740991
(2^53 - 1
).
Beyond this value, integer arithmetic may lose accuracy due to floating-point limitations.
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991
Number.MIN_SAFE_INTEGER
The smallest integer that can be safely represented: -9007199254740991
(-(2^53 - 1)
).
console.log(Number.MIN_SAFE_INTEGER); // -9007199254740991
Number.POSITIVE_INFINITY
Represents positive infinity, a value larger than any finite number.
Results from operations like dividing by zero:
console.log(Number.POSITIVE_INFINITY); // Infinity
console.log(1 / 0); // Infinity
Number.NEGATIVE_INFINITY
Represents negative infinity, a value smaller than any finite number.
Results from operations like dividing a negative number by zero:
console.log(Number.NEGATIVE_INFINITY); // -Infinity
console.log(-1 / 0); // -Infinity
Number.NaN
Represents “Not-a-Number”, indicating an invalid or undefined numerical result (e.g., 0 / 0
or Math.sqrt(-1)
).
console.log(Number.NaN); // NaN
console.log(0 / 0); // NaN
console.log(Number.isNaN(NaN)); // true