← ACARA Digital Technologies Years 9–10

Debugging with console.log

A temporary line that prints a variable's value while the program runs, so you can see where it goes wrong. Add a label to tell values apart, then remove it once fixed.

Understanding Debugging with console.log in ACARA Digital Technologies Years 9–10

What it does: The log is the first line inside the function, so it shows the incoming parameter values before any other code runs. A temporary log prints a variable's value so you can see where it goes wrong. A label tells you which variable the printed value belongs to, especially when many values are logged. Debugging logs are temporary. Remove them once the bug is fixed to keep the console clean. The label and the value are separate arguments, so a comma must go between them. Adding labels like console.log('score:', score) makes each value identifiable in the console. Every console.log call needs a matching closing bracket, like console.log('total:', total);.

Common mistakes: There is a comma missing between the label and the value. It should be console.log('b:', b); so the label and value are separate arguments. The closing bracket of console.log is missing. It should be console.log('w', w); so the debug line runs without a syntax error.

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 710–727) and word search (Modules 710–742).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Why do you add a temporary console.log(total) inside a function you are debugging?
To make the function run fasterTo see the value of total while the program runs
Matches
console.log(score); console.log(lives);
↓
The values are logged without labels, so the output shows two bare numbers and you cannot tell which is score and which is lives.
Applying
Meanings
Term
console.log(label, value)
Meaning
A temporary line that prints a variable's value while the program runs, so you can see where it goes wrong. Add a label to tell values apart, then remove it once fixed.
Practice
// Temporary logs: delete once fixed
Testing
Gaps
console.log("n:", );
Check Answer
Spots
2 console.log('a:', a);
3 console.log('b:' b);

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

The 'Ermine' badge — Tundra Streak, 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. Why do you add a temporary console.log(total) inside a function you are debugging?
A. To see the value of total while the program runs ✓
B. To make the function run faster
A temporary log prints a variable's value so you can see where it goes wrong.
2. Which log line is easier to understand in a busy console?
A. console.log('price:', price); ✓
B. console.log(price);
A label tells you which variable the printed value belongs to, especially when many values are logged.
3. You suspect a function receives the wrong input. Where is the best place to log first?
A. At the top of the function, logging the parameter ✓
B. After the function has been deleted
Logging a parameter on entry shows exactly what the function was given.
4. A loop gives a wrong total. Which log helps you see how the value changes each time?
A. console.log('sum:', sum); after the loop only
B. console.log('sum:', sum); inside the loop body ✓
Logging inside the loop prints the value on every pass, so you can spot the step where it goes wrong.
5. You fixed the bug and the program works. What should you do with your debugging logs?
A. Leave them in so the console stays full
B. Remove them ✓
Debugging logs are temporary. Remove them once the bug is fixed to keep the console clean.

Match the Pairs

console.log('price:', price); → Prints the label 'price:' and the value of price, so you can see what the variable holds at that moment.
for (let i = 0; i < 3; i++) { console.log('i:', i); } → Logs the value of i on every pass of the loop, so you can watch how it changes each time.
Log a parameter on entry to a function to check what value the function actually received → function area(w, h) { console.log('w:', w, 'h:', h); }
Once the bug is fixed, remove the temporary debugging line so the console stays clean → function total(a, b) { return a + b; }
console.log(score); console.log(lives); → The values are logged without labels, so the output shows two bare numbers and you cannot tell which is score and which is lives.
console.log('total: ' + total; → The closing bracket is missing, so this is a syntax error and nothing is logged.

Key Term

console.log(label, value)
A temporary line that prints a variable's value while the program runs, so you can see where it goes wrong. Add a label to tell values apart, then remove it once fixed.

Fill in the Blanks

1. function square(n) { console.log("n:", n); return n * n; }
Hint: Type the parameter name so its value is logged as soon as the function starts.
2. for (let i = 0; i < 3; i++) { console.log("i:", i); }
Hint: Type the loop variable so you can see its value on every pass of the loop.
3. let score = 10 * 2; console.log("score:", score);
Hint: Type the console method name that prints a labelled value to the console.
4. let sum = 0; for (const n of nums) sum += n; console.log("sum:", sum);
Hint: Type the variable name whose value you want to check after the loop finishes.
5. let x = 4 * 5; // console.log("x:", x);
Hint: Type the symbols that turn a fixed debug line into a comment so it no longer runs.

Spot the Error

Question 1
A function total(a, b) {
B console.log('a:', a);
C console.log('b:' b);
D return a + b;
E }
Line C — There is a comma missing between the label and the value. It should be console.log('b:', b); so the label and value are separate arguments.
Question 2
A function area(w, h) {
B console.log('w', w;
C return w * h;
D }
Line B — The closing bracket of console.log is missing. It should be console.log('w', w); so the debug line runs without a syntax error.
Question 3
A let sum = 0;
B for (let n of [4, 5, 6]) {
C console.log('n', 'n');
D sum += n;
E }
Line C — The value is in quotes, so it prints the text n every time instead of the variable's value. It should be console.log('n', n); to see each loop value.
Question 4
A let price = 20;
B let qty = 3;
C console.log('price', qty);
D console.log(price * qty);
Line C — The label says price but the value logged is qty. A wrong label is misleading when you debug. It should be console.log('qty', qty);
Question 5
A function greet(name) {
B console.log('name', nme);
C return 'Hi ' + name;
D }
Line B — The variable name is misspelt, so JavaScript throws a ReferenceError. The parameter is called name, so log name on entry to the function.

Student with a class code? Join your class →