Every programmer debugs
Professional developers spend a big part of every day finding bugs. It isn't failure — it's detective work. Today you'll learn a calm, step-by-step way of debugging.
The detective's method
- Read the error. Which line? What kind of error?
- Say what you expected and what actually happened.
- Look inside with console.log — check what values really are.
- Change one thing at a time, then run again.
function average(a, b) {
const total = a + b;
console.log("total is", total);
return total / 2;
}
console.log(average("4", 6));console.log("label", value) with a label makes your debugging logs easy to tell apart.