Operators
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition / Concatenation | 1 + 2 => 3 |
- | Subtraction | 5 - 3 => 2 |
* | Multiplication | 2 * 3 => 6 |
/ | Division | 6 / 3 => 2 |
% | Modulo | 7 % 3 => 1 |
Increment/Decrement
javascript
x++ // Post-increment
++x // Pre-increment
x-- // Post-decrement
--x // Pre-decrementComparison Operators
| Operator | Description |
|---|---|
== | Equal |
<> | Not equal |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
Logical Operators
| Operator | Description |
|---|---|
&& | Logical AND |
|| | Logical OR |
! | Logical NOT |
Ternary Operator
javascript
condition ? valueIfTrue : valueIfFalseOptional Chaining
javascript
obj?.property
obj?.nested?.valueSpread Operator
javascript
[...arr1, ...arr2, newItem]
{ ...obj1, ...obj2, newProp: value }Operator Precedence
From highest to lowest:
- Parentheses
() - Member access
.[]?. - Unary operators
-!~++--delete - Multiplication/Division/Modulo
*/% - Addition/Subtraction
+- - Comparison
<><=>= - Equality
==<> - Logical AND
&& - Logical OR
|| - Ternary
?: - Assignment
=
