Mathematical Operators

You can do math equations with these operators:

Operator

Example(s)

add

+

x = 2 + 3; // x is now 5

subtract

-

y = 6 - 9; // y is now -3

multiply

*

z = 5 * 3; // z is now 15

divide

/

a = 9 / 3; // a is now 3

modulus / remainder

%

b = 4 % 3; // b is now 1

exponent

^

c = 3^3; // c is now 27

These operators, followed by an equals sign is a shortcut to adjusting the variable:

Operator

Example(s) let's say x = 3 in all cases

add this

+=

x += 3; // x is now 6

subtract this

-=

x -= 9; // x is now -6

multiply this by

*=

x *= 3; // x is now 9

divide this by

/=

x /= -1; // x is now -3

modulus / remainder of this

%=

x %= 2; // x is now 1

exponent of this

^=

x ^= 3; // x is now 27

Last updated