Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

Modulus Operator (JavaScript)

Divides the value of one expression by the value of another, and returns the remainder.

result = number1 % number2

Any variable.


Any numeric expression.


Any numeric expression.

The modulus, or remainder, operator divides number1 by number2and returns only the remainder as result. The sign of result is the same as the sign of number1. The value of result is between 0 and the absolute value of number2.

The following code shows how to use the modulus operator.

var modResult = 19 % 6.7;

// Output: 5.6

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.