Js Number Properties in JavaScript
? JavaScript Number Properties
JavaScript provides static properties on the Number object that describe important constants and numeric limits. These are not methods, but read-only values.
? List of Number Properties
| Property | Description |
|---|---|
Number.MAX_VALUE | Largest possible number (~1.79e+308) |
Number.MIN_VALUE | Smallest possible positive number (> 0, ~5e-324) |
Number.POSITIVE_INFINITY | Special value representing positive infinity |
Number.NEGATIVE_INFINITY | Special value representing negative infinity |
Number.NaN | Not-a-Number value (e.g. result of 0/0) |
Number.MAX_SAFE_INTEGER | Largest safe integer in JS (2?³ - 1 = 9007199254740991) |
Number.MIN_SAFE_INTEGER | Smallest safe integer (-2?³ + 1) |
Number.EPSILON | Difference between 1 and the smallest value > 1 |
? Examples
1. Max and Min Value
console.log(Number.MAX_VALUE); // 1.7976931348623157e+308console.log(Number.MIN_VALUE); // 5e-3242. Infinity
console.log(1 / 0); // Infinityconsole.log(Number.POSITIVE_INFINITY); // Infinityconsole.log(Number.NEGATIVE_INFINITY); // -Infinity3. NaN (Not-a-Number)
console.log(0 / 0); // NaNconsole.log(Number.NaN); // NaNconsole.log(isNaN("abc")); // true4. Safe Integers
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991console.log(Number.MIN_SAFE_INTEGER); // -90071992547409915. Number.EPSILON
let a = 0.1 + 0.2;console.log(Math.abs(a - 0.3) < Number.EPSILON); // true? Notes
Number.MAX_VALUEis not the maximum integer, it's the max floating-point number.Numbers larger than
MAX_SAFE_INTEGERmay result in precision issues.EPSILONis useful for comparing floating point numbers due to rounding errors.
Would you like a comparison between Number and BigInt for large or precise number handling?