Javascript - Operator Modulus Operator

Introduction

The modulus (remainder) operator is represented by a percent sign (%) and is used in the following way:

var result = 26 % 5;    //equal to 1 

The modulus operator behaves differently for special values, as follows:

Operand
Result
If the operands are numbers
regular arithmetic division is performed, and the remainder is returned.
If the dividend is an infinite number and the divisor is a finite number
the result is NaN.
If the dividend is a finite number and the divisor is 0
the result is NaN.
If Infinity is divided by Infinity
the result is NaN.
If the dividend is a finite number and the divisor is an infinite number
the result is the dividend.
If the dividend is zero and the divisor is nonzero
the result is zero.
If either operand isn't a number
it is converted to a number behind the scenes using Number() and then the other rules are applied.

Related Topic