JavaScript - Operators Overview

Overview

Estimated time: 20–30 minutes

Operators act on values and variables. This page orients you to the categories; subsequent pages cover each in depth.

Learning Objectives

  • Recognize operator categories and their use cases.
  • Know where to find details for each category.

Prerequisites

Categories

  • Arithmetic: + - * / % ** ++ --
  • Comparison: == != === !== < > <= >=
  • Logical: && || ! (and logical assignment &&= ||= ??=)
  • Bitwise: & | ^ ~ << >> >>>
  • Assignment: = += -= *= /= %= **= etc.
  • Conditional (ternary): cond ? a : b
  • typeof and delete
  • Spread/Rest: ...
  • Nullish coalescing: ??
  • Precedence and associativity

Example

const a = 2 + 3 * 4; // 14 (multiplication before addition)
const b = (2 + 3) * 4; // 20
const user = { name: 'Ada', role: null };
const role = user.role ?? 'guest'; // 'guest'

Common Pitfalls

  • Using == instead of === can coerce values unexpectedly.
  • Confusing short-circuit || with nullish coalescing ?? (which treats 0 and '' as valid values).
  • Ignoring precedence can change results; use parentheses for clarity.

Checks for Understanding

  1. What’s the difference between == and ===?
  2. When should you prefer ?? over ||?
Show answers
  1. === compares without coercion; == allows type coercion and can yield surprising results.
  2. Prefer ?? when you want to treat only null and undefined as “missing,” keeping 0/''/false as valid.

Exercises

  1. Show a case where value || 'fallback' differs from value ?? 'fallback'.
  2. Rewrite an expression to make precedence explicit using parentheses.