JavaScript Number Properties

JavaScript provides several properties for the Number object that offer useful constants and information about the limits and behavior of numbers in JavaScript.

1. Number.MAX_VALUE

The largest positive numeric value representable in JavaScript.

console.log(Number.MAX_VALUE);  // Output: 1.7976931348623157e+308

Try It Now

Usage: Used to determine the maximum possible value a JavaScript Number can have.

 

2. Number.MIN_VALUE

The smallest positive numeric value representable in JavaScript (close to zero but not negative).

console.log(Number.MIN_VALUE);  // Output: 5e-324

Try It Now

Usage: Used to determine the smallest positive value.

3. Number.POSITIVE_INFINITY

Represents positive infinity. Returned when a number exceeds Number.MAX_VALUE.

console.log(Number.POSITIVE_INFINITY);  // Output: Infinity
console.log(1 / 0);                     // Output: Infinity

Try It Now

Usage: Used to represent values greater than Number.MAX_VALUE.

4. Number.NEGATIVE_INFINITY

Represents negative infinity. Returned when a number is less than -Number.MAX_VALUE.

console.log(Number.NEGATIVE_INFINITY);  // Output: -Infinity
console.log(-1 / 0);                    // Output: -Infinity

Try It Now

Usage: Used to represent values less than -Number.MAX_VALUE.

5. Number.NaN

Represents a special “Not-a-Number” value. This is returned when a mathematical operation doesn’t result in a valid number.

console.log(Number.NaN);  // Output: NaN
console.log(0 / 0);       // Output: NaN

Try It Now

Usage: Used to identify operations that result in an undefined or unrepresentable value.

6. Number.EPSILON

Represents the smallest interval between two representable numbers.

console.log(Number.EPSILON);  // Output: 2.220446049250313e-16

Try It Now

Usage: Useful for determining equality of floating-point numbers, taking into account the limitations of precision.

7. Number.MAX_SAFE_INTEGER

The maximum safe integer in JavaScript (2^53 - 1).

console.log(Number.MAX_SAFE_INTEGER);  // Output: 9007199254740991

Try It Now

Usage: Used to ensure operations on integers remain precise.

8. Number.MIN_SAFE_INTEGER

The minimum safe integer in JavaScript (-(2^53 - 1)).

console.log(Number.MIN_SAFE_INTEGER);  // Output: -9007199254740991

Try It Now

Usage: Used to ensure operations on negative integers remain precise.

9. Number.isFinite()

Determines whether the passed value is a finite number.

console.log(Number.isFinite(123));        // Output: true
console.log(Number.isFinite(Infinity));   // Output: false
console.log(Number.isFinite('123'));      // Output: false

Try It Now

Usage: Useful for checking whether a number is within the finite range.

10. Number.isInteger()

Determines whether the passed value is an integer.

console.log(Number.isInteger(123));      // Output: true
console.log(Number.isInteger(123.45));   // Output: false

Try It Now

Usage: Used to check if a value is a whole number.

 

Summary of JavaScript Number Properties

  • Number.MAX_VALUE and Number.MIN_VALUE provide the range of representable numbers.
  • Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY represent the extremes of the numeric spectrum.
  • Number.NaN is used to represent invalid number results.
  • Number.EPSILON, Number.MAX_SAFE_INTEGER, and Number.MIN_SAFE_INTEGER provide precision and safety information.