← ACARA Digital Technologies Years 7–8

Curly braces and indentation

Curly braces group the statements that belong to an if, loop or function. The code inside the braces is indented so you can see which block it belongs to.

Understanding Curly braces and indentation in ACARA Digital Technologies Years 7–8

What it does: The function body sits between { and }, with the line inside indented so you can see it belongs to greet. Both indented statements are inside the while block, so both are grouped by the same pair of braces. Every opening brace { needs a matching closing brace } on its own line. The wrong version is missing the closing brace. Putting } on its own line makes it easy to see where the block ends. JavaScript uses braces, not indentation, to find the end of a block. A missing } causes a syntax error. Curly braces mark which statements belong to the loop, and the indentation makes that body easy to see.

Common mistakes: The function block is closed with a round bracket. It must be closed with a curly brace } on its own line. The opening curly brace { is missing. It should go at the end of the first line: function add(a, b) {.

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 583–598) and word search (Modules 583–613).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which if statement uses curly braces correctly?
if (score > 10) { console.log("Win"); }if (score > 10) { console.log("Win");
Matches
if (age >= 13) { console.log("Teen");
↓
The closing brace } is missing. Every opening { needs a matching } on its own line after the block.
Applying
Meanings
Term
{ }
Meaning
Curly braces group the statements that belong to an if, loop or function. The code inside the braces is indented so you can see which block it belongs to.
Practice
let lives = 3;
Testing
Gaps
if (score >= 50)
Check Answer
Spots
2 return score > 50;
3)

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

The 'Spider' badge — Web Weaver, 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. Which if statement uses curly braces correctly?
A. if (score > 10) { console.log("Win"); } ✓
B. if (score > 10) { console.log("Win");
Every opening brace { needs a matching closing brace } on its own line. The wrong version is missing the closing brace.
2. Where does the opening brace usually go in a for loop?
A. On the same line as the for (...) part ✓
B. On a line far below the loop, after the body
The opening brace goes at the end of the first line: for (let i = 0; i < 3; i++) {
3. Where does the closing brace } go?
A. On its own line, lined up with the start of the if, loop or function ✓
B. At the end of the last statement inside the block, on the same line
Putting } on its own line makes it easy to see where the block ends.
4. Which function is indented correctly?
A. function greet() { console.log("Hi"); }
B. function greet() { console.log("Hi"); } ✓
Statements inside the braces are indented (usually 2 or 4 spaces) so you can see they belong to the function.
5. True or false: Curly braces { } group the statements that belong to an if, loop or function.
A. False
B. True ✓
Everything between { and } is the body of the block. It only runs as part of that if, loop or function.

Match the Pairs

if (score > 50) { console.log("Pass"); } → The opening brace { sits on the same line as the if. The statement inside the braces is indented, and the closing brace } sits on its own line.
for (let i = 0; i < 3; i++) { console.log(i); } → The braces group the statements that repeat in the loop. Only the indented code inside { } runs each time.
Curly braces group all the statements that belong to a function, and the body is indented inside them. → function greet() { console.log("Hi"); }
Several statements can share one block. Every line inside the braces is indented the same amount. → while (lives > 0) { lives--; console.log(lives); }
if (age >= 13) { console.log("Teen"); → The closing brace } is missing. Every opening { needs a matching } on its own line after the block.
if (age >= 13) { console.log("Teen"); } → The opening brace is not on the same line as the if, and the statement inside is not indented, so the block is hard to read.

Key Term

{ }
Curly braces group the statements that belong to an if, loop or function. The code inside the braces is indented so you can see which block it belongs to.

Fill in the Blanks

1. if (score >= 50) { console.log("Pass"); }
Hint: Type the symbol that opens the block on the same line as the condition.
2. for (let i = 0; i < 3; i++) { console.log(i); }
Hint: Type the symbol that closes the block, on its own line.
3. function sayHi() { console.log("Hi!"); }
Hint: Type the symbol that opens the function body after the brackets.
4. function double(n) { return n * 2; }
Hint: Type the keyword that sends a value back, written as an indented line inside the function block.
5. while (lives > 0) { lives--; }
Hint: Type the symbol that ends the loop block so the loop body is fully enclosed.

Spot the Error

Question 1
A function pass(score) {
B return score > 50;
C )
Line C — The function block is closed with a round bracket. It must be closed with a curly brace } on its own line.
Question 2
A function add(a, b)
B return a + b;
C }
Line A — The opening curly brace { is missing. It should go at the end of the first line: function add(a, b) {
Question 3
A let ok = true;
B if (ok) [
C console.log("Go");
D }
Line B — A square bracket [ was used to open the block. An if block must open with a curly brace { on the same line as the if.
Question 4
A let n = 3;
B while (n > 0) (
C console.log(n);
D n--;
E }
Line B — A round bracket ( was used to open the loop body. A block must open with a curly brace {.
Question 5
A function isEven(num) {
B if (num % 2 === 0) {
C return true;
D )
E return false;
F }
Line D — The if block is closed with a round bracket. It must be closed with a curly brace }, on its own line, lined up with the if.

Student with a class code? Join your class →