← ACARA Digital Technologies Years 7–8

ReferenceError: a name that is not defined

An error shown when code uses a variable or function name that has not been declared, often from a typo, wrong capital letter, wrong scope or using it before declaring it.

Understanding ReferenceError: a name that is not defined in ACARA Digital Technologies Years 7–8

What it does: bonus only exists inside the curly braces of the if block, so it is not defined when logged outside. The line that logs lives runs before the let declaration, so the name is not available yet. JavaScript is case-sensitive, so Score and score are different names. Only score was declared, so Score causes a ReferenceError. The name live was never declared. It is a misspelling of lives, so JavaScript cannot find it. The capital N matters. Typing the name exactly as it was declared removes the ReferenceError.

Common mistakes: scor is a misspelt name. The variable was declared as score, so JavaScript throws ReferenceError: scor is not defined. It should be console.log(score);. JavaScript is case sensitive, so Score and score are different names. Only score was declared, so Score causes a ReferenceError. Use score.

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 624–634) 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
let score = 10; console.log(Score); What happens?
ReferenceError: Score is not definedIt prints 10
Matches
let playerName = 'Mia'; console.log(playername);
↓
The variable is declared as playerName but used as playername, so the capital N is missing and the name is not defined
Applying
Meanings
Term
ReferenceError
Meaning
An error shown when code uses a variable or function name that has not been declared, often from a typo, wrong capital letter, wrong scope or using it before declaring it.
Practice
let score = 10;
Testing
Gaps
console.log();
Check Answer
Spots
2score += 5;
3console.log(scor);

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

The 'Sperm Whale' badge — Deep Sea Champion, 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. let score = 10; console.log(Score); What happens?
A. It prints 10
B. ReferenceError: Score is not defined ✓
JavaScript is case-sensitive, so Score and score are different names. Only score was declared, so Score causes a ReferenceError.
2. Which line causes a ReferenceError?
A. let lives = 3; console.log(live); ✓
B. let lives = 3; console.log(lives);
The name live was never declared. It is a misspelling of lives, so JavaScript cannot find it.
3. What is the cause of this error? console.log(total); let total = 5;
A. The number 5 is the wrong data type
B. The variable is used before it is declared ✓
The line using total runs before let total is declared, so JavaScript throws a ReferenceError. Declare the variable first.
4. if (true) { let bonus = 5; } console.log(bonus); What happens?
A. ReferenceError: bonus is not defined ✓
B. It prints 5
A let variable only exists inside the braces where it was declared. Outside the block, bonus is not defined.
5. Which message tells you a name has not been declared?
A. ReferenceError: playerName is not defined ✓
B. SyntaxError: Unexpected token '}'
A ReferenceError means a name could not be found. A SyntaxError means the code is written in a way JavaScript cannot read.

Match the Pairs

ReferenceError: score is not defined → The program used the name score, but no variable or function called score has been declared
let score = 5; console.log(Score); → Causes a ReferenceError because Score with a capital S is a different name from score
Using a variable outside the block where it was declared with let causes a ReferenceError → if (true) { let bonus = 10; } console.log(bonus);
Using a variable before declaring it can cause a ReferenceError → console.log(lives); let lives = 3;
let playerName = 'Mia'; console.log(playername); → The variable is declared as playerName but used as playername, so the capital N is missing and the name is not defined
let total = 4; console.log(totl); → The name totl is misspelt, so JavaScript cannot find a variable with that name

Key Term

ReferenceError
An error shown when code uses a variable or function name that has not been declared, often from a typo, wrong capital letter, wrong scope or using it before declaring it.

Fill in the Blanks

1. let coins = 10; console.log(coins);
Hint: Type the variable name exactly as it was declared, with the same spelling.
2. let speed = 9; console.log(speed);
Hint: Type the keyword that declares the variable before it is used.
3. let msg = ""; if (true) { msg = "Hi"; } console.log(msg);
Hint: Type the keyword that declares the variable outside the block so the last line can see it.
4. function sayHi() { console.log("Hi"); } sayHi();
Hint: Type the function name exactly as it was declared.
5. let score = 0; score = score + 1; console.log(score);
Hint: Type the variable name, matching the capital letters used in the declaration.

Spot the Error

Question 1
A let score = 10;
B score += 5;
C console.log(scor);
Line C — scor is a misspelt name. The variable was declared as score, so JavaScript throws ReferenceError: scor is not defined. It should be console.log(score);
Question 2
A let score = 20;
B let bonus = 5;
C console.log(Score + bonus);
Line C — JavaScript is case sensitive, so Score and score are different names. Only score was declared, so Score causes a ReferenceError. Use score.
Question 3
A let Age = 12;
B age++;
C console.log(age);
Line A — This declares Age with a capital A, but the next lines use age. The name age is never declared, so line 2 throws a ReferenceError. It should be let age = 12;
Question 4
A let width = 4;
B let hieght = 3;
C let area = width * height;
D console.log(area);
Line B — The variable is declared as hieght, but line 3 uses height. Because height was never declared, JavaScript throws ReferenceError: height is not defined. It should be let height = 3;
Question 5
A let total = 0;
B for (let i = 1; i <= 3; i++) {
C total = total + j;
D }
E console.log(total);
Line C — The loop counter is called i. The name j was never declared, so it causes a ReferenceError. It should be total = total + i;

Student with a class code? Join your class →