Do you know what will be the output of this code?
JavaScript
console.log(-7 % 3);
Show answer and explanation
The answer is -1.
% is a remainder operator, not a true modulo. The result takes the sign of the left operand: -7 = 3 × -2 + (-1).
For a positive modulo, use ((n % m) + m) % m.