← ACARA Digital Technologies Years 7–8

TypeError: assignment to a constant variable

The error JavaScript shows when code tries to give a new value to a const variable. Fix it by declaring the variable with let if its value needs to change.

Understanding TypeError: assignment to a constant variable in ACARA Digital Technologies Years 7–8

What it does: lives is declared with const, so the second line tries to change a constant and JavaScript throws a TypeError. This message is about giving a new value to a const. A missing semicolon is a different kind of problem. Use const for values that never change, like pi. A score changes during the game, so it needs let. Shorthand updates such as += and ++ also reassign a variable, so they fail on const just like = does. A TypeError also appears when you try to call something that is not a function, so check the message and what the name holds.

Common mistakes: score is given a new value on line 4, so it cannot be a const. Reassigning it gives TypeError: Assignment to constant variable. Declare it with let score = 0; instead. lives-- changes the value, but a const cannot change. This causes TypeError: Assignment to constant variable. Use let lives = MAX_LIVES; because lives changes.

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
A student writes const score = 0; then score = 10; What happens when the code runs?
TypeError: Assignment to constant variablescore becomes 10 with no error
Matches
const points = 10; points += 5;
↓
points is a const, so += tries to give it a new value and causes a TypeError. Declare it with let instead.
Applying
Meanings
Term
TypeError: Assignment to constant variable
Meaning
The error JavaScript shows when code tries to give a new value to a const variable. Fix it by declaring the variable with let if its value needs to change.
Practice
const player = 'Mia';
Testing
Gaps
score = 0;
Check Answer
Spots
2console.log(name);
3const score = 0;

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

The 'Coelacanth' badge — Living Fossil, 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. A student writes const score = 0; then score = 10; What happens when the code runs?
A. TypeError: Assignment to constant variable ✓
B. score becomes 10 with no error
A const variable cannot be given a new value after it is created, so JavaScript stops with a TypeError.
2. Which declaration lets you change the value later without an error?
A. let lives = 3; ✓
B. const lives = 3;
Use let for values that will change, like lives in a game. const is locked after the first value.
3. The console shows: TypeError: Assignment to constant variable. What is the cause?
A. The code tried to reassign a const variable ✓
B. The code forgot a semicolon at the end of a line
This message is about giving a new value to a const. A missing semicolon is a different kind of problem.
4. Which code will cause a TypeError?
A. let total = 5; total = total + 1;
B. const total = 5; total = total + 1; ✓
total = total + 1 gives total a new value. This is fine with let but fails with const.
5. How do you fix this code? const count = 0; count++;
A. Change count++ to count--
B. Change const to let ✓
count++ changes the variable, so it must be declared with let. Using -- would still change a const and fail.

Match the Pairs

TypeError: Assignment to constant variable. → The error JavaScript shows when code tries to give a new value to a const variable.
let score = 0; score = 5; → A variable declared with let can be given a new value, so no TypeError happens.
Reassigning a const variable causes a TypeError → const lives = 3; lives = 2;
Fix the error by changing const to let when the value must change → let lives = 3; lives = 2;
const points = 10; points += 5; → points is a const, so += tries to give it a new value and causes a TypeError. Declare it with let instead.
const name = "Sam"; name(); → name holds a string, not a function, so calling it with () causes a TypeError. Only call names that are functions.

Key Term

TypeError: Assignment to constant variable
The error JavaScript shows when code tries to give a new value to a const variable. Fix it by declaring the variable with let if its value needs to change.

Fill in the Blanks

1. let score = 0; score = score + 5;
Hint: Type the keyword that declares a variable whose value can be changed later.
2. const lives = 3; lives = 2; // Error type: TypeError
Hint: Type the name of the error JavaScript shows when you reassign a const variable.
3. const name = "Sam"; name(); // TypeError: name is not a function
Hint: Type the variable name that the error message says is not a function.
4. const lives = 3; lives = 2; // TypeError: Assignment to constant variable
Hint: Type the word from the error message that describes the kind of variable that cannot be reassigned.
5. const PI = 3.14159; console.log(PI);
Hint: Type the keyword used for a value that should never change.

Spot the Error

Question 1
A const name = "Ava";
B console.log(name);
C const score = 0;
D score = score + 10;
Line C — score is given a new value on line 4, so it cannot be a const. Reassigning it gives TypeError: Assignment to constant variable. Declare it with let score = 0; instead.
Question 2
A const MAX_LIVES = 3;
B const lives = MAX_LIVES;
C lives--;
D console.log(lives);
Line B — lives-- changes the value, but a const cannot change. This causes TypeError: Assignment to constant variable. Use let lives = MAX_LIVES; because lives changes.
Question 3
A let count = 0;
B const limit = 3;
C while (count < limit) {
D limit += 1;
E }
Line D — limit is a const, so adding to it causes TypeError: Assignment to constant variable. The loop should update the counter that changes, count += 1;
Question 4
A const price = 5;
B price = price + 2;
C console.log(price);
Line A — price is changed on line 2, so a const will throw TypeError: Assignment to constant variable. Use let price = 5; for values that change.
Question 5
A const age = 12;
B console.log(age());
C console.log(age + 1);
Line B — age holds a number, not a function, so the brackets () cannot call it. JavaScript shows TypeError: age is not a function. It should be console.log(age);

Student with a class code? Join your class →