Modulus Operator
In JavaScript, arithmetic Modulus operator is used to find the remainder of the division of two numeric values.
Syntax
%
symbol is used for arithmetic modulus operator
arithmetic modulus operator takes two values/variables as operands and returns the remainder in the division of the left operand divided by the right operand
a % b //remainder when a divided by b
6 % 4 //remainder when 6 divided by 4
Examples
- Find the remainder when value in
a
is divided byb
.
var a = 6;
var b = 4;
var remainder = a % b;
console.log(remainder);