Expressions are JavaScript commands that assign a value to the variables. Operators are elements that perform actions within the expression. The most commonly used operators are arithmetic operators and assignment operators.
| Operators | Comments | Examples |
|---|---|---|
| + | add two values together | var j = i + 5; |
| - | subtracts one value from another | var j = i - 5; |
| * | multiplies two values together | var j = i * 5; |
| / | divides one value by another | var j = i / 5; |
| % | the remainder after dividing one value by another | var j = i % 5; |
| ++ | increments a value by 1 | var j = i++; |
| -- | decrements a value by 1 | var j = i--; |
| - | changes the sign of a value | var j = -i; |
Expressions assign values by using assignment operators. The most common assignment operation is the equals sign (=). JavaScript also provides several shortcuts for most commonly used types of the assignment operator:
| Operators | Comments |
|---|---|
| += | x += y is equivalent to x = x + y |
| -= | x -= y is equivalent to x = x - y |
| *= | x *= y is equivalent to x = x + y |
| /= | x /= y is equivalent to x = x / y |
| %= | x %= y is equivalent to x = x % y |