0Pricing
JavaScript Academy · Lesson

if/else and switch — core patterns

Write clear conditions with if/else and switch; use guard clauses for early exits.

Intro

Goal: Choose the right conditional. Start with if/else, add else if for multiple branches, and use switch for clean value matching.

if/else and switch — core patterns — illustration 1

if/else basics

If the condition is true, run the first block; otherwise run the else block.

// if/else — choose between two paths
const score = 72;

if (score >= 60) {
  console.log("Pass");
} else {
  console.log("Retry");
}
if/else and switch — core patterns — illustration 2

All lessons in this course

  1. if/else and switch — core patterns
  2. Loops: for, while, do…while, for…of vs for…in
  3. Early Returns and Guard Clauses
← Back to JavaScript Academy