Numerical Operator Shortcuts
Some Math Operations are so common that many languages provide shortcut syntax, for example: x = x + 1; can also be written as x++, or as x += 1;
When modifying the value of a variable based on the current value of the variable, the syntax for addition would be:
var x = 10;
x = x + 3; // increment x by 3
x = x - 4; // decrease x by 4
x = x * 2 // multiply x by 2
x = x / 5 //divide x by 5
///The shortcut syntax for the above
x += 3;
x -= 4;
x *= 2;
x /= 5;
Last updated
Was this helpful?