What is the difference between %= and %?
Hi @kirubiel
You will most likely have seen this %=
in the following scenario.
let value = 5;
value %= 2; // 1
Essentially, it’s short hand for:
let value = 5;
value = value % 5;
%
on it’s own is just the remainder (or modulo) operator.
Note: any arithmetic operator can be used in the same fasion, so:
let value = 4;
value += 2; // 6
value *= 2; // 8
value /= 2; // 2
value -= 2; // 2
1 Like
Ohhh yeah I forgot about that. I forgot it was shorthand. Thanks a lot.
1 Like