← ACARA Digital Technologies Years 7–8

Reading an error message and its line number

Part of an error message: the file and line number where JavaScript noticed the error. Check that line first, but the real mistake may be a line earlier.

Understanding Reading an error message and its line number in ACARA Digital Technologies Years 7–8

What it does: TypeError is the error name and the text after it is the description, here telling you a const value was changed. The missing ] is on line 1, but JavaScript only notices the problem on line 2 when it reaches console, so the error points to line 2. Start at the reported line. If it looks fine, check the line before it, because the real mistake may be earlier. The description explains the problem in words. A ReferenceError means a name was used that JavaScript does not know. The message gives you clues. Read it carefully before changing any code.

Common mistakes: The closing bracket is missing, so JavaScript reports a SyntaxError and gives line 3 as the place to look. It should be console.log(score + bonus);. The closing quote after Hi is missing, so the string never ends. The SyntaxError (Invalid or unexpected token) points to line 2. It should be console.log("Hi " + name);.

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 611–623) and word search (Modules 611–634).

Take this worksheet further — free with Cloodit

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

Learning
Duo
An error message says 'script.js:5'. What does the 5 tell you?
JavaScript noticed the error on line 5, so check there firstThe program has exactly 5 errors in it
Matches
let age = 12; console.log(agee);
↓
The message says ReferenceError: agee is not defined at line 2. The variable name is misspelled and should be age.
Applying
Meanings
Term
script.js:3
Meaning
Part of an error message: the file and line number where JavaScript noticed the error. Check that line first, but the real mistake may be a line earlier.
Practice
// Error name + description, then check that line
Testing
Gaps
// : scoree is not defined
Check Answer
Spots
2let bonus = 5;
3console.log(score + bonus;

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

The 'Abyssal Dragon' badge — Deep Sea Legend, 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. An error message says 'script.js:5'. What does the 5 tell you?
A. The program has exactly 5 errors in it
B. JavaScript noticed the error on line 5, so check there first ✓
The number after the file name is the line number where JavaScript noticed the problem. It is the best place to start looking.
2. Which part of an error message names the kind of problem, such as SyntaxError or ReferenceError?
A. The line number, at the end of the file name
B. The error name, at the start of the message ✓
The error name tells you the type of error. The line number tells you where JavaScript noticed it.
3. The console shows 'script.js:4 Uncaught SyntaxError: Unexpected token'. Where should you start looking?
A. Line 4, and then the line above it ✓
B. Line 1, because errors always start there
Start at the reported line. If it looks fine, check the line before it, because the real mistake may be earlier.
4. Line 2 is: let name = "Sam and line 3 is: console.log(name);. The error is reported on line 3. Which is true?
A. The real mistake may be on line 2, the missing closing quote ✓
B. The real mistake must be on line 3, because that is where the error was reported
JavaScript can only notice a problem when it gets confused. The unclosed quote on line 2 made line 3 look wrong.
5. An error message says 'ReferenceError: score is not defined'. What does the description tell you?
A. JavaScript could not find a variable called score ✓
B. The variable score has the wrong data type
The description explains the problem in words. A ReferenceError means a name was used that JavaScript does not know.

Match the Pairs

script.js:3 → The file name and line number where JavaScript noticed the error. Check line 3 first, but the real mistake may be a line earlier.
ReferenceError: score is not defined → The error name and description: JavaScript cannot find anything called score, so check for a typo or a missing let.
An error message names the type of error and describes what went wrong → TypeError: Assignment to constant variable.
The real mistake may be a line earlier than the line number in the error message → let nums = [1, 2 console.log(nums);
let age = 12; console.log(agee); → The message says ReferenceError: agee is not defined at line 2. The variable name is misspelled and should be age.
function hi() { console.log("Hi"); hi(); → The closing } is missing. JavaScript reports the error at the end of the file (Unexpected end of input), not on line 1 where the function started.

Key Term

script.js:3
Part of an error message: the file and line number where JavaScript noticed the error. Check that line first, but the real mistake may be a line earlier.

Fill in the Blanks

1. console.log(scoree); // ReferenceError: scoree is not defined
Hint: Type the name of the error type shown when JavaScript cannot find a name.
2. let age = 12; age = ; // Error is reported at script.js:2
Hint: Type the line number of the broken line.
3. const max = 5; max = 6; // TypeError : Assignment to constant variable.
Hint: Type the error name that goes with changing a const.
4. // Error at script.js:5 // Check line 5 first, then line 4
Hint: Type the line number just before the reported line, where the real mistake may be.
5. console.log(x); // script.js:1 ReferenceError
Hint: Type the file name that appears before the line number in an error message.

Spot the Error

Question 1
A let score = 10;
B let bonus = 5;
C console.log(score + bonus;
Line C — The closing bracket is missing, so JavaScript reports a SyntaxError and gives line 3 as the place to look. It should be console.log(score + bonus);
Question 2
A const name = "Mia";
B console.log("Hi + name);
C console.log(name.length);
Line B — The closing quote after Hi is missing, so the string never ends. The SyntaxError (Invalid or unexpected token) points to line 2. It should be console.log("Hi " + name);
Question 3
A let total = 0;
B total = total + 5;
C console.log(totl);
Line C — The variable name is misspelt, so JavaScript throws a ReferenceError: totl is not defined, and names line 3. It should be console.log(total);
Question 4
A const lives = 3;
B let score = 0;
C score += 10;
D lives = lives - 1;
Line D — lives is a const, so it cannot be reassigned. JavaScript shows TypeError: Assignment to constant variable on line 4. It should create a new variable: let left = lives - 1;
Question 5
A let items = ["pen", "ruler";
B console.log(items[0]);
C console.log(items.length);
Line A — The closing square bracket is missing on line 1. The error message may point at the end of this line or even a line later, so check the line before it too. It should be let items = ["pen", "ruler"];

Student with a class code? Join your class →