โž•remainder (%)

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

JS โŸฉ operator โŸฉ arithmetic โŸฉ 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