Conditionals and Branching
LockedLesson 4 of 25 · Syntax · Easy
Mastery0% of 85%
Up next: Variables and Primitive Types (~7 min) →Finish these first:Operators and Comparisons →Or pass the tests below to unlock it now.
1
The big idea
An if statement lets JavaScript make a decision. It tests a condition inside ( ...
Think of it like this: Think of an `if` statement like a checkpoint: if the rule in `( ... )` is true, JavaScript runs the lines inside `{ ... }`.
Key words (tap to learn):
2
Read the lesson
An if statement lets JavaScript make a decision. It tests a condition inside ( ... ), and runs the code inside { ... } only when that condition is true:
let score = 92;
let grade = "";
if (score >= 90) {
grade = "A";
}
Notice we do not write let again when updating an existing variable (grade = "A";).
3
Quick check
How do you write an `if` check in JavaScript?
4
2 sample tests, 1 hiddenYour challenge
Write an if statement: when age >= 18, set status = "adult";.
Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.conditionals (92% overlap). Branching control flow: if/else and switch/match expressions.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Conditionals and Branching.
Mastery0%
Learn this first
- Operators and ComparisonsNot yet