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.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
TypeError: Assignment to constant variableFill in the Blanks
Spot the Error
Student with a class code? Join your class →