← JavaScript

If Statements

Runs a block of code only when the condition inside its parentheses is true.

Understanding If Statements in JavaScript

What it does: Parentheses hold the condition that decides if the block runs. Curly braces contain the block of code to execute. If the condition is false, the block is skipped entirely. JavaScript is case-sensitive, so 'if' must be lowercase. The condition always goes inside round brackets. The block of code to run is wrapped in { }. = assigns a value - use === or another comparison operator instead. Conditions often use comparison operators to test values.

Common mistakes: 'if' must be lowercase - a capital I causes an error. The condition needs parentheses: if (age >= 12).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 11–25) and word search (Modules 1–29).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does an if statement run its block only when the condition is true?
YesNo
Matches
if age >= 12 { console.log("Hi"); }
↓
Wrong - the condition needs parentheses
Applying
Meanings
Term
if
Meaning
Runs a block of code only when the condition inside its parentheses is true.
Practice
let age = 12;
Testing
Gaps
(age >= 12) {
Check Answer
Spots
1If (age >= 12) {
2console.log("Hi");

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hippopotamus' badge — Savannah Titan, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does an if statement run its block only when the condition is true?
A. No
B. Yes ✓
If the condition is false, the block is skipped entirely.
2. Must 'if' be written in lowercase?
A. Yes ✓
B. No
JavaScript is case-sensitive, so 'if' must be lowercase.
3. Does an if condition need to be wrapped in parentheses?
A. Yes ✓
B. No
The condition always goes inside round brackets.
4. Does an if statement's code block use curly braces?
A. Yes ✓
B. No
The block of code to run is wrapped in { }.
5. Is = a valid way to write a condition inside an if statement?
A. Yes
B. No ✓
= assigns a value - use === or another comparison operator instead.

Match the Pairs

if (age >= 12) { ... } → Runs the block only if age is 12 or more
if (score > 50) { ... } → Runs the block only if score is greater than 50
Wraps the condition being tested → ( )
Wraps the code that runs when the condition is true → { }
if age >= 12 { console.log("Hi"); } → Wrong - the condition needs parentheses
if (x = 5) { console.log(x); } → Wrong - use === for comparison, not = for assignment

Key Term

if
Runs a block of code only when the condition inside its parentheses is true.

Fill in the Blanks

1. if (age >= 12) {
Hint: Type the keyword that starts a conditional statement.
2. if (score > 50) {
Hint: Type the operator that checks if one value is greater.
3. if (name === "Sam") {
Hint: Type the symbol that opens the code block.
4. if (isReady) { console.log("Go"); }
Hint: Type the symbol that closes the code block.
5. if (temp < 0) {
Hint: Type the keyword that starts a conditional statement.

Spot the Error

Question 1
A If (age >= 12) {
B console.log("Hi");
C }
Line A — 'if' must be lowercase - a capital I causes an error.
Question 2
A if age >= 12 {
B console.log("Hi");
C }
Line A — The condition needs parentheses: if (age >= 12).
Question 3
A console.log("Hi")
B if (age >= 12) {
C }
Line A — This line is missing a semicolon, but that's not required in JS.
Question 4
A console.log("Win");
B if (score > 50) [
C ]
Line B — Code blocks use curly braces {}, not square brackets [].
Question 5
A if (ready) {
B ]
C console.log("Go");
Line B — The block must close with }, not ].

Student with a class code? Join your class →