NextGen Knowledge Center

Arithmetic Operators

These operators are used to perform arithmetic between variables and/or values. In this table, the y-variable has a value of 5 to explain the JavaScript Arithmetic operators:

OperatorDescriptionExampleResult of xResult of y
+Additionx=y+2 (5+2)75
-Subtractionx=y-2 (5-2)35
*Multiplicationx=y*2 (5*2)105
/Divisionx=y/2 (5/2)2.55
%Modulus (division remainder)x=y%2 (remainder is 1 for the equation 5/2)15
++Incrementx=++y (++6)6 (a)6 (b)
x=y++ (6++)5 (c)6 (b)
--Decrementx=--y (--4)4 (d)4 (e)
x=y-- (4--)5 (f)4 (e)
(a) The increment occurs before the variable, so x is the incremented value of y, which is 6; (b) The value is 6 because y, which is 5, is increased by 1 for this operator; (c) The increment occurs after the variable, so x is the original value of y, which is 5; (d) The decrement occurs before the variable, so x is the decremented value of y, which is 4; (e) The value is 4 because y, which is 5, is decreased by 1 for this operator; (f) The decrement occurs after the variable, so x is the original value of y, which is 5.