remainder (%)

remainder `r = a % b`, `r` has the same sign as `a`.

JSoperatorarithmetic ⟩ remainder (%)

a%b returns

  • NaN, if one of the operands is NaN /a = ±Infinity / b = ±0.

  • a, if a = ±0 /b = ±Infinity.

  • r=a-b*q where:

    • q is the integer such that:

    • r has the same sign asa, while being as close to 0 as possible.

// ⭐️ `a` decides the sign of the remainder
 5 % 2    //  1
-5 % 2    // -1   

👉 table of operators, remainder vs. modulo vs. mod

remainder (%) and modulo are different 👉 remainder vs. modulo vs. mod

% operator

Last updated