Debugging
In one line
Debugging is the process of finding, understanding, and fixing errors (bugs) in your code.
In simple words
Debugging is what you do when your code does not work correctly. A "bug" is an error — the program crashes, produces the wrong output, or behaves unexpectedly. Debugging is the detective work of finding the cause and fixing it.
The debugging process usually involves: (1) reproducing the error, (2) reading the error message, (3) isolating where the problem occurs, (4) understanding why it happens, and (5) fixing it and verifying the fix.
Common debugging tools include: console.log to print variable values, breakpoints in a debugger (Chrome DevTools, VS Code debugger), and step-through execution to watch the code run line by line. Good debugging is systematic — you form a hypothesis, test it, and narrow down the cause.
Example
// Buggy code
function average(a, b) {
return a + b / 2; // Bug: should be (a + b) / 2
}
// Debug: log the values
console.log(average(10, 20)); // 20 (wrong, should be 15)
// Fix: add parentheses
function averageFixed(a, b) {
return (a + b) / 2;
}
console.log(averageFixed(10, 20)); // 15 (correct)The bug is operator precedence: b / 2 is computed before adding a. Adding parentheses fixes the order of operations.
Related terms
Related Resources
Related Lessons
- Debugging Basics
Learn how to debug systematically.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.