Operations
At the beginning of the course, we used the *
operator to demonstrate multiplication and we use the /
operator for division.
Division remainder
The remainder operator %
can also be used to return the division remainder.
Here's an example,
4 % 2; // Division remainder is 0
9 % 2; // Division remainder is 1
The division remainder of 8 % 2 is calculated as follows:
8 / 2 = 4 => the division remainder is 0 because 8 = 4 * 2 + 0
In the case of 7 % 2:
7 / 2 = 3 (rounded) => the division remainder is 1 because 7 = 3 * 2 + 1.
In two chapters, we'll use the division remainder to determine whether a number is even or odd.