Modulus(%) Arithmetic Operator in JavaScript
Last Updated :
28 May, 2024
Improve
The modulus (%) arithmetic operator in JavaScript returns the remainder after dividing one number by another. It is used for tasks like determining even or odd numbers, cycling through values within a range, and managing periodic events in programming.
Syntax:
a%b
Return Type: Remainder of the operands.
Example 1: We will check the remainder with Number and Infinity in this example.
console.log(100%23);
console.log(Infinity%20);
Output:
8
NaN
Example 2: In this example, we will use the modulus operator on the negative number and NaN
console.log(-100%23);
console.log(NaN%20);
Output:
-8
NaN
Supported Browsers: