Operators
There are 2 types of operators in JavaScript.
Assignment operators and arithmetic operators.
The tables below describes and shows examples of the operators.
Arithmetic
Operator | Description | Example | Result |
+ | Addition | | a=1+7; | a=8
- | Subtraction | a=8-2; | a=6 |
* | Multiplication | a=8*3; | a=24 |
/ | Division | a=21/3; | a=7 |
% | Modulus | a=20%7; | a=6 |
++ | Increment | a++; | a=a+1 |
-- | Decrement | a--; | a=a-1 |
Assignment
Operator | Description | Example | Result |
= | Assignment | a=8 | a=8; |
+= | Add rightside value to original value | a=1; a+=7; | a=8 |
-= | Subtract rightside value from original value | a=8; a-=2; | a=6 |
*= | Multiply rightside value to original value | a=8; a*=3; | a=24 |
/= | Divide leftside value by rightside value | a=21; a/=3; | a=7 |
%= | Same as divide, but output the modulus | a=20; a%=7; | a=6 |
|