JavaScript Number.EPSILON

The JavaScript Number.EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.

The EPSILON property has a value of 252 that is approximately 2.2204460492503130808472633361816E-16.

It is a non-writable, non-enumerable, and non-configurable property.

Number.EPSILON can be used to test the equality of the floating-point numbers.

The syntax to access the EPSILON constant is:


EPSILON is accessed using the Number class name.

Example: Using Number.EPSILON

value = Number.EPSILON;
console.log(value); // 2.220446049250313e-16

a = 0.1;
b = 0.2;
c = 0.3;

console.log(a + b == c); // false

console.log(a + b - c < value); // true



In JavaScript, due to how floating-point numbers are implemented, 0.1 + 0.2 is not exactly equal to 0.3. So, instead of using this ordinary checking method that does not work, we can instead check if their difference is smaller than Number.EPSILON.

Recommended Reading:

Did you find this article helpful?