Common bugs in classes and objects
Common class bugs: forgetting new, leaving out this. in the constructor, swapping the arguments, or misspelling a property so it reads undefined.
Understanding Common bugs in classes and objects in ACARA Digital Technologies Years 9–10
What it does: this.name is the object's property and name is the parameter. Without this., the value is lost when the constructor finishes. Name comes first and age second. Writing new Pet(3, 'Rex') would swap the values and give the wrong properties. Calling a class without new throws: Class constructor Pet cannot be invoked without 'new'. Arguments are matched by position. Swapping them puts 3 in name and 'Rex' in age. nmae is a misspelt property name. JavaScript does not throw an error, it just gives undefined. The error message tells you the fix: add new before the class name. A class must be called with new. The fix is const p = new Pet('Rex', 3);.
Common mistakes: A class constructor cannot be called without new. Pet("Rex") throws "Class constructor Pet cannot be invoked without 'new'". It should be new Pet("Rex"). The word new is missing. Calling Dog("Bo") like a normal function throws an error. It should be new Dog("Bo") so a new object is created.
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 743–781) and word search (Modules 743–809).
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
new Pet(name, age)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →