Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What is -7 % 3 in JavaScript?

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.

Take the full quiz Next question →

More Basics questions

  1. What happens when you reassign a const in JavaScript?
  2. Why is typeof null "object" in JavaScript?
  3. What is the difference between == and === in JavaScript?
  4. What does Array.push() return in JavaScript?
  5. Is a var loop variable accessible after a for loop?

Related topics