JavaScript Number.EPSILON Property Method
The JavaScript Number.EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.
A floating point number, is a positive or negative whole number with a decimal point. For example, 1.2, 2.3, 4.5, ...etc.
Syntax
Following is the syntax of JavaScript Number.EPSILON() property −
Number.EPSILON
Parameters
- It does not accept any parameter
Return value
This property has no return return value.
Example 1
In the following example, we are using the JavaScript Number.EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.
<html>
<head>
<title>JavaScript Number.EPSILON Property</title>
</head>
<body>
<script>
var result = Number.EPSILON;
document.write("Value of the epsilon: ", result);
</script>
</body>
</html>
Output
The above program produces the epsilon value as −
Value of the epsilon: 2.220446049250313e-16
Example 2
The following is another example of the JavaScript Number.EPSILON property. We define a function named equal(x, y), which compares value with Number.EPSILON, and return true or false based on the comparison.
<html>
<head>
<title>JavaScript Number.EPSILON Property</title>
</head>
<body>
<script>
function equal(x, y) {
return (x-y) < Number.EPSILON;
}
let x = 10.1;
let y = 10.2;
document.write("x = ", x, ", y = ", y);
//callig the function
document.write("<br>The result of '(x-y) < Number.EPSILON': ", equal(x, y));
document.write("<br>The result of '(x = x+y, y) < Number.EPSILON': ", equal(x+y, y));
</script>
</body>
</html>
Output
After executing the above program, it will return the following output −
x = 10.1, y = 10.2 The result of '(x-y) < Number.EPSILON': true The result of '(x = x+y, y) < Number.EPSILON': false