You may also be interested in learning about Number.EPSILON (the floating point epsilon) which is required when dealing with number equality...
For example, this is an incorrect way to compare numbers:
> 0.1 + 0.2 === 0.3
false
This is the proper way to compare numbers:
a = 0.1 + 0.2
b = 0.3
> Math.abs(a - b) < Number.EPSILON
true
This means the difference is smaller than the smallest quantity that can be represented in floating point number, and every JS number is a floating point number.
Not knowing about this can cause many issues if you deal with values representing currency.
Epsilon is not the smallest quantity that can be represented. Its the smallest amount that can be added to a number between 1 and 2. If its added to 2 the result is 2. We need to add 2 * Number.EPSILON to 2 to add anything. 4 * E to 4, 8 * E to 8, 16 * E to 16 etc.
For example, this is an incorrect way to compare numbers:
This is the proper way to compare numbers: This means the difference is smaller than the smallest quantity that can be represented in floating point number, and every JS number is a floating point number.Not knowing about this can cause many issues if you deal with values representing currency.