JavaScript control flow

JavaScript operators, if/else, loops, and switch statements

Learn JavaScript operators and control flow with focused lessons on arithmetic operators, comparisons, equality, if/else, ternary expressions, logical operators, nullish coalescing, while loops, for loops, break, continue, and switch statements.

Control flow lessons and concepts

  1. Operators and expressions

    Combine values with arithmetic, assignment, string concatenation, precedence, and everyday expression syntax.

    Outcome: Write expressions that compute values clearly and predictably.

    • JavaScript operators
    • arithmetic operators
    • operator precedence
    Study Basic operators, maths
  2. Comparisons and equality

    Compare numbers, strings, booleans, null, and undefined with strict equality and ordering rules.

    Outcome: Choose comparison operators that avoid accidental type conversion bugs.

    • JavaScript comparisons
    • strict equality
    • comparison operators
    Study Comparisons
  3. If, else, and ternary expressions

    Run different code paths with if statements, else branches, and compact conditional expressions.

    Outcome: Represent simple decisions without making control flow hard to follow.

    • JavaScript if else
    • ternary operator
    • conditional branching
    Study Conditional branching: if, '?'
  4. Logical operators

    Use AND, OR, and NOT operators for boolean logic, guards, defaults, and short-circuit evaluation.

    Outcome: Combine conditions and guard code paths with explicit boolean intent.

    • JavaScript logical operators
    • && operator
    • || operator
    Study Logical operators
  5. Nullish coalescing

    Use ?? when fallback values should apply only to null or undefined, not every falsy value.

    Outcome: Avoid replacing valid values such as 0, false, or empty strings.

    • nullish coalescing
    • ?? operator
    • JavaScript fallback value
    Study Nullish coalescing operator '??'
  6. While and for loops

    Repeat work with while loops, for loops, counters, conditions, break, and continue.

    Outcome: Iterate through repeated work while controlling when loops stop.

    • JavaScript loops
    • for loop JavaScript
    • while loop JavaScript
    Study Loops: while and for
  7. Switch statements

    Route one value through multiple named branches with switch, case, default, and break.

    Outcome: Use switch when one value maps cleanly to several branches.

    • JavaScript switch
    • switch statement
    • case default break
    Study The "switch" statement
  8. Function control flow

    Connect branching and loops to functions so repeated decisions become reusable code blocks.

    Outcome: Move decision logic into functions that are easier to test and reuse.

    • JavaScript functions
    • return statement
    • function control flow
    Study Functions