Question 15
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log(-7 % 3, 7 % -3, 5.5 % 2);
- A 2 -2 1.5
- B -1 1 1.5 Correct
- C -1 -1 1
- D 1 1 1.5
Correct Answer: Option B
JavaScript's % is a remainder, not a mathematical modulo: its sign follows the dividend. It also works on decimals: 5.5 = 2 × 2 + 1.5.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!