Modulo is a mathematical operation that finds the remainder when an integer is divided by another. It is frequently expressed as mod or symbolized as % , therefore, the expression 5 mod 3 can also be written as 5 % 3 , where 5 is the dividend and 3 is the divisor.

Given two positive numbers, * a* and

*,*

**n***modulo*

**a***(abbreviated as*

**n***mod*

**a***) is the remainder of the division of*

**n***by*

**a***, where*

**n***is the dividend and*

**a***is the divisor.*

**n**For example, the expression 9 % 2 would evaluate to 1 because 9 divided by 2 has a quotient of 4 and a remainder of 1.

The expression 10 % 2 would evaluate to 0 because 10 divided by 2 has a quotient of 5 and a remainder of 0.

### Practical Uses of Modulo

*Examples below assume that you have the basic knowledge of JavaScript and jQuery library. The use of modulo is not limited to JavaScript but Ill be giving my examples here in JavaScript.*

**Leap Year**

To check if the year, y, is a leap year, you use the expression, y % 4 . The division of a leap year by 4 has 0 remainder, therefore, y % 4 should evaluate to 0 if y is a leap year. The example below shows a function to check if a given year is a leap year.

**Card Sharing**

A card pack contains 55 cards to be shared among 4 players. Each player must have a maximum of 5 cards on his tray, which means, 20 cards would be given out from the card pack. The example below shows a function that does the card sharing.

**Check Multiples of a Number**

An even number is known as a number that can be divided by 2 without having any remainder (having 0 remainder). The expression, 4 % 2 evaluates to 0 because 4 is an even number, while the expression 9 % 2 evaluates to 1 because 9 is an odd number. Therefore, 4 is a multiple of 2, but 9 is not a multiple of 2.

The expression, 25 % 5 evaluates to 0 because 25 is a multiple of 5, while the expression 28 % 5 evaluates to 3 because 28 divided 5 has a remainder of 3, therefore, 28 is not a multiple of 5.

**Time Calculation**

Modulo operator can also be used in time calculations.

Example

Annabel visited her friend at 2:00pm (14:00). She left her friends place after spending 30hrs with her. At what time of the day did she leave her friends place?

Christian Ezeani is a web developer, software engineer, and project manager at Cyberpull Technologies and TeamCYB. My interests range from technology to writing.