The remainder operator % gives the remainder of the division of two numbers.
Example:
5 % 2 = 1 because
Math.floor(5 / 2) = 2 (Quotient)
2 * 2 = 4
5 − 4 = 1 (Remainder)
Usage:
In mathematics, a number can be checked to be even or odd by checking the remainder of the division of the number by 2.
13 % 2 = 1 (13 is Odd)
48 % 2 = 0 (48 is Even)
Note:
The remainder operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers.
Hint:
Learn more about Remainder (%)
12 % 5
// 2
-1 % 2
// -1
1 % -2
// 1
NaN % 2
// NaN
1 % 2
// 1
2 % 3
// 2
-4 % 2
// 0
5.5 % 2
// 1.5