Commenting out code to find a bug
Putting // in front of a line makes JavaScript skip it, so you can switch code off to find a bug. Remove the // to switch it back on.
Understanding Commenting out code to find a bug in ACARA Digital Technologies Years 7–8
What it does: The // stops the line from running, so you can see if the bug disappears without deleting the code. Taking the // away switches the line back on, so the program works as it did before. Anything after // on a line is skipped. Putting // at the start switches off the whole line. Putting it at the end switches off nothing. If the problem goes away when a line is switched off, that line is a good suspect. Comment out one line at a time to isolate the bug. Deleting the // switches the code back on. Adding more slashes keeps it switched off.
Common mistakes: # is not a comment in JavaScript, so this line is a syntax error. To switch a line off you put // in front of it: // console.log(score * 2);. A single / does not start a comment, so JavaScript tries to read it as division and gives a syntax error. A comment needs two slashes: //.
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
// console.log(total);Fill in the Blanks
Spot the Error
Student with a class code? Join your class →