Essential JavaScript

Going Further

Modulus and Remainders

If we want to get the remainder of a division operation, we can use the modulo operator (%). Try it:

  • 5 % 2

The result is 1.

Remainder Refresher

5 divided by 2 is exactly 2.5. If we are dividing using only whole numbers, then the answer would be 2 instead.

Think of it this way. If we have 5 pennies and split them into two even piles, each pile would have 2 pennies and there would be 1 penny left over. That is the remainder.

Learning Goals

  • I can use the modulo operator to get the remainder after division

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines