It's the remainder operator and is used to get the remainder after integer division. Lots of languages have it. For example:
10 % 3 // = 1 ; because 3 * 3 gets you 9, and 10 - 9 is 1.
Apparently it is not the same as the modulo operator entirely.
Answer from MarioDS on Stack OverflowAppeon
docs.appeon.com โบ pb2025 โบ powerscript_reference โบ mod_func.html
Mod - - PowerScript Reference
Obtains the remainder (modulus) of a division operation.
4JS
4js.com โบ online_documentation โบ fjs-fgl-manual-html โบ fgl-topics โบ c_fgl_operators_MODULUS.html
Genero Business Development Language - MOD
The MOD operator returns the remainder, as an integer, from the division of the integer part of two numbers.
char - How can I use modulo operator (%) in JavaScript? - Stack Overflow
How can I use modulo operator (%) ... for JavaScript projects? ... Someone might want to rename this question from modulo to remainder because it pops up in Google searches for a modulo operator in JS. ... It's the remainder operator and is used to get the remainder after integer division... More on stackoverflow.com
Understanding the JavaScript Modulo Operator
A quick peek at the documentation would reveal that % in JavaScript is not modulo, it's the remainder operator (or can be found in the ECMAScript specification ). This is confusing to many people, and unfortunately articles like these don't help by using the wrong terminology. The difference occurs when one of the values is negative. -21 % 4 The result of this is 3 for "mod" and -1 for "rem". This can be confusing behavior, if for example, to implement an isOdd function, you might think of something like this: function isOdd(n) { return n % 2 === 1 } However, this is wrong! It returns false for an input of -1. More on reddit.com
math - How to perform an integer division, and separately get the remainder, in JavaScript - Stack Overflow
1. If you're going to compute the remainder rem anyway, you can get the quotient div faster without flooring: (y - rem) / x. 2. By the way the modulo operation by Donald Knuth's recommended definition (sign-matches-divisor, not the remainder i.e. Euclidean modulus, nor the JavaScript ... More on stackoverflow.com
Why do different programming languages have a different definition for Modulus operation?
Of course it will not be standardized, because changing how the mod works would break millions of existing programs. The "why" is difficult. Maybe some used the definition that would make the implementation faster with the available processors, or the one more coherent from a nathematical point of view. In practice, most of times you use positive operands. I've programmed as an amateur for decads before encountering a negative operand (last week), so knowing it was tricky, I checked it. More on reddit.com
Videos
02:23
You'll Use This More Than You Think... JavaScript Modulo Operator ...
04:40
Use Cases for Remainders in Programming (with JavaScript) - YouTube
04:45
Javascript Modulo Operator Explained | Understanding modulo rest ...
03:41
18. Javascript Division and Modulus Operator. - YouTube
04:45
Modulo Operation in JavaScript - Coderbyte - YouTube
05:23
The Remainder Operator in JavaScript | Modulo % - YouTube
DigitalOcean
digitalocean.com โบ community โบ tutorials โบ how-to-do-math-in-javascript-with-operators
How To Do Math in JavaScript with Operators | DigitalOcean
August 25, 2021 - Division is particularly useful ... that is slightly less familiar is the modulo (sometimes known as modulus) operator, which calculates the remainder of a quotient after division....
MDN Web Docs
developer.mozilla.org โบ en-US โบ docs โบ Web โบ JavaScript โบ Reference โบ Operators โบ Remainder
Remainder (%) - JavaScript | MDN
For two values of the same sign, ... which can make them differ by one unit of d. To obtain a modulo in JavaScript, in place of n % d, use ((n % d) + d) % d....
W3Schools
w3schools.com โบ js โบ js_arithmetic.asp
JavaScript Arithmetic
In arithmetic, the division of two integers produces a quotient and a remainder. In mathematics, the result of a modulo operation is the remainder of an arithmetic division.
Reddit
reddit.com โบ r/programming โบ understanding the javascript modulo operator
r/programming on Reddit: Understanding the JavaScript Modulo Operator
December 12, 2023 - The post explains the Modulo operator (%) in JavaScript, which is often misunderstood and appears to produce random values. The author clarifies its function by redefining how we think about division, emphasizing that it's about dividing a number into equally-sized groups without fractional remainders.
Top answer 1 of 16
1905
For some number y and some divisor x compute the quotient (quotient)[1] and remainder (remainder) as:
const quotient = Math.floor(y/x);
const remainder = y % x;
Example:
const quotient = Math.floor(13/3); // => 4 => the times 3 fits into 13
const remainder = 13 % 3; // => 1
[1] The integer number resulting from the division of one number by another
2 of 16
519
I'm no expert in bitwise operators, but here's another way to get the whole number:
var num = ~~(a / b);
This will work properly for negative numbers as well, while Math.floor() will round in the wrong direction.
This seems correct as well:
var num = (a / b) >> 0;
Note: Only use ~~ as a substitution for Math.trunc() when you are confident that the range of input falls within the range of 32-bit integers.
Educative
educative.io โบ answers โบ what-is-the-modulo-operator-in-javascript
What is the modulo operator in JavaScript?
The modulo operator is represented by the % character in JavaScript. It returns the remainder of two integers that have been divided. ... As the remainder will always be less than the divisor, modulo operators can be very useful in restricting ...
2ality
2ality.com โบ 2019 โบ 08 โบ remainder-vs-modulo.html
Remainder operator vs. modulo operator (with JavaScript code)
Example 4: -5 mod 3 === 1 (dividend is โ5, divisor is 3)