Back to JavaScript Notes
Topic #301

Number Properties

By the end of this lesson, you can use JavaScript number properties such as Number.MAX_SAFE_INTEGER, Number.MAX_VALUE, and Number.EPSILON to reason about integer limits, finite range, and floating-point precision.

What it is

Number properties are static constants attached to the Number constructor. They describe limits and precision characteristics of JavaScript’s number system, which uses IEEE-754 double-precision floating-point values.

Number.MAX_SAFE_INTEGER is the largest integer that can be represented exactly in JavaScript: 2^53 - 1, or 9007199254740991. Integers above this value may lose precision because the floating-point format cannot represent every whole number exactly.

Number.MAX_VALUE is the largest finite number JavaScript can represent, approximately 1.7976931348623157e+308. It is not the same as the largest safe integer.

Number.EPSILON is the difference between 1 and the next representable number above 1. It is useful when comparing floating-point numbers because operations like 0.1 + 0.2 may not produce an exact result.

Related properties include Number.MIN_SAFE_INTEGER, Number.MIN_VALUE, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, and Number.isSafeInteger().

Why it matters

  • It helps you avoid silent integer overflow when working with IDs, counters, or timestamps.
  • It clarifies the difference between “largest finite number” and “largest exact integer.”
  • It supports safer floating-point comparisons using a small tolerance instead of strict equality.
  • It helps you decide when to switch from Number to BigInt.
  • It prevents bugs caused by assuming JavaScript can represent every large whole number exactly.

Syntax or steps

Access these constants directly from the Number object. Do not create a new Number instance to use them.

Number.MAX_SAFE_INTEGER;
Number.MAX_VALUE;
Number.EPSILON;
Number.isSafeInteger(value);

For integer safety, compare values against Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER, or use Number.isSafeInteger(). For floating-point equality, compare the absolute difference against a tolerance.

Example

const safeLimit = Number.MAX_SAFE_INTEGER;
const maxFinite = Number.MAX_VALUE;
const epsilon = Number.EPSILON;

console.log(safeLimit);
console.log(safeLimit + 1 === safeLimit + 2);
console.log(maxFinite * 2);

console.log(0.1 + 0.2 === 0.3);
console.log(Math.abs((0.1 + 0.2) - 0.3) < epsilon);

function nearlyEqual(a, b) {
  return Math.abs(a - b) < epsilon;
}

console.log(nearlyEqual(0.1 + 0.2, 0.3));
  • safeLimit stores the largest safe integer.
  • console.log(safeLimit) prints 9007199254740991.
  • safeLimit + 1 === safeLimit + 2 prints true because numbers beyond the safe integer range can lose precision.
  • maxFinite * 2 prints Infinity because the result exceeds the largest finite number.
  • 0.1 + 0.2 === 0.3 prints false due to floating-point rounding.
  • The epsilon comparison prints true because the tiny difference is smaller than Number.EPSILON.

Common mistakes

  • Using Number.MAX_VALUE to check integer safety. Fix: use Number.MAX_SAFE_INTEGER or Number.isSafeInteger().
  • Comparing floating-point numbers with ===. Fix: compare the absolute difference against a tolerance.
  • Using Number.EPSILON as a universal absolute tolerance. Fix: for very large or very small numbers, use a relative tolerance based on the magnitude of the values.
  • Assuming all large integers are safe. Fix: if you need exact arbitrary-size integers, use BigInt.

When to use it

Goal Use Why
Check the largest exact integer Number.MAX_SAFE_INTEGER It marks the boundary where integer precision may fail.
Check the largest finite number Number.MAX_VALUE It is about overflow to Infinity, not exact integer representation.
Compare floating-point results Number.EPSILON It helps account for tiny rounding errors.
Work with very large exact integers BigInt It supports integers beyond the safe Number range.

Practice

Guided exercise: Write a function called isSafeInt(n) that returns true only when n is a safe integer.

Solution hint: Use Number.isSafeInteger(n).

function isSafeInt(n) {
  return Number.isSafeInteger(n);
}

console.log(isSafeInt(Number.MAX_SAFE_INTEGER));
console.log(isSafeInt(Number.MAX_SAFE_INTEGER + 1));

Expected output:

true
false

Challenge: Improve nearlyEqual(a, b) so it uses a relative tolerance instead of only Number.EPSILON. Hint: compare the difference to a small fraction of the larger absolute value.

Quick check

Question: Which constant tells you the largest integer JavaScript can represent exactly?

Answer: Number.MAX_SAFE_INTEGER.

Summary

JavaScript number properties describe the limits and precision of the Number type. Number.MAX_SAFE_INTEGER protects exact integer behavior, Number.MAX_VALUE describes finite overflow, and Number.EPSILON helps compare floating-point values safely.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Number Properties – FAQs

Quick answers about learning Number Properties in JavaScript.

This free note from Coding Now Tech Institute explains Number Properties in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including Number Properties, is 100% free with no signup required.
With focused practice, most students grasp Number Properties in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now