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 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");
}

All lessons in this course
- if/else and switch — core patterns
- Loops: for, while, do…while, for…of vs for…in
- Early Returns and Guard Clauses