Lesson 8
Debugging foundations
Build a practical mental model for debugging foundations and use it in working JavaScript.
By the end, you will be able to…
- Explain debugging foundations in your own words
- Use debugging foundations in a small program
- Recognize and debug a common failure mode
Build the mental model
Debugging is a repeatable loop, not luck: reproduce the failure, read the first error message from the top, form one hypothesis, test it with the smallest possible change, then rerun.
Syntax and working example
Read the code from inputs to output. Predict what it prints, then run it and change one value.
Why this matters
Beginners lose hours guessing randomly at fixes; the reproduce-read-hypothesize-test loop turns debugging into a predictable skill.
Real-world example
Senior engineers debug production incidents with this exact loop under real time pressure — it scales from a typo to a distributed system.
Common mistakes
- Changing several lines before rerunning to see which one mattered
- Reading only the last line of a stack trace instead of the first thrown error
- Guessing at a fix instead of forming a testable hypothesis
Try it yourself
Challenge
Find and fix the reference error in the broken total() function above.
Knowledge check
What is the first step in a reliable debugging loop?
Summary
Reproduce, read the first error, hypothesize, change one thing, rerun — repeat until fixed.