Python Conditionals & If / Else Branching
JavaScript uses if, else if, and else statements to execute code blocks based on boolean condition evaluations. Each branch is enclosed in curly braces creating its own block scope.
"An if/else tree is like a railroad track switch. If the sensor detects a green signal, the train stays on track A; otherwise, it switches over to track B."
Deep Dive: How It Works
Condition Evaluation: Conditions are evaluated to truthy or falsy values.
Block Scope: Variables declared with const and let inside an if block cannot be accessed outside it.
Chaining Branches: Use else if to test multiple mutually exclusive conditions sequentially.
Syntax Blueprint
if (score >= 90) { ... } else if (score >= 80) { ... } else { ... }Branches execute top-to-bottom and stop at the first condition that evaluates to truthy.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using assignment (=) instead of equality (===) in condition.Why it happens: if (x = 5) assigns 5 to x and evaluates to truthy, always entering the branch.
How to fix: Always use === or !== when comparing values inside if statements.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Grade evaluator conditional
Given const score = 85;
If score >= 90, log "Grade: A".
Else if score >= 80, log "Grade: B".
Else log "Grade: C".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.