Assignment Operators
These operators are used to assign values to JavaScript variables. In this table, the x-variable has a value of 10, and the y-variable has a value of 5 to explain the JavaScript Assignment operators:
Operator | Description | Example | Same As | Result |
---|---|---|---|---|
= | assign | x=y | x=y (5) | x=5 |
+= | add and assign | x+=y | x=x+y (10+5) | x=15 |
-= | subtract and assign | x-=y | x=x-y (10-5) | x=5 |
*= | multiply and assign | x*=y | x=x*y (10*5) | x=50 |
/= | divide and assign | x/=y | x=x/y (10/5) | x=2 |
%= | modulus (division remainder) and assign | x%=y | x=x%y (remainder is 0 for the equation 10/2) | x=0 |