Skip to content

Operators

Arithmetic Operators

OperatorDescriptionExample
+Addition / Concatenation1 + 2 => 3
-Subtraction5 - 3 => 2
*Multiplication2 * 3 => 6
/Division6 / 3 => 2
%Modulo7 % 3 => 1

Increment/Decrement

javascript
x++     // Post-increment
++x     // Pre-increment
x--     // Post-decrement
--x     // Pre-decrement

Comparison Operators

OperatorDescription
==Equal
<>Not equal
<Less than
>Greater than
<=Less than or equal
>=Greater than or equal

Logical Operators

OperatorDescription
&&Logical AND
||Logical OR
!Logical NOT

Ternary Operator

javascript
condition ? valueIfTrue : valueIfFalse

Optional Chaining

javascript
obj?.property
obj?.nested?.value

Spread Operator

javascript
[...arr1, ...arr2, newItem]
{ ...obj1, ...obj2, newProp: value }

Operator Precedence

From highest to lowest:

  1. Parentheses ()
  2. Member access . [] ?.
  3. Unary operators - ! ~ ++ -- delete
  4. Multiplication/Division/Modulo * / %
  5. Addition/Subtraction + -
  6. Comparison < > <= >=
  7. Equality == <>
  8. Logical AND &&
  9. Logical OR ||
  10. Ternary ?:
  11. Assignment =