Operators and expressions

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.

Arithmetic operators

OperatorsCommentsExamples
+ 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;




Assignment operators

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:

OperatorsComments
+= 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