JavaScript Arithmetic and Assignment Operators
Arithmetic Operators
Arithmetic operators used to perform arithmetic operations between variables.
| Operator |
Description |
Example |
| + |
Addition |
x=y+2 |
| - |
Subtraction |
x=y-2 |
| * |
Multiplication |
x=y*2 |
| / |
Division |
x=y/2 |
| % |
Modulus |
x=y%2 |
| ++ |
Increment |
x=++y |
| -- |
Decrement |
x=--y |
Assignment Operators
| Operator |
Description |
| = |
x=y |
| += |
x+=y |
| -= |
x-=y |
| *= |
x*=y |
| /= |
x/=y |
| %= |
x%=y |
Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between variables or values.
| Operator |
Description |
| == |
is equal to |
| = = = |
is exactly equal to (value and type) |
| ! = |
is not equal to |
| > |
is greater than |
| < |
is less than |
| >= |
is greater than or equal to |
| <= |
is less than or equal to |
Logical Operators
Logical operators are used to determine the logic between variables or values.
| Operator |
Description |
| && |
and |
| ! |
not |
| || |
or |
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
Syntax:
variable_name=(condition) ? value1 : value2