## What is Debugging?
Debugging is finding and fixing errors in code. Every developer spends significant time debugging - code rarely works perfectly the first time.
Good debugging separates junior developers from experienced ones. Juniors guess randomly. Experienced developers debug systematically.
## Common Bug Types
**Syntax Errors**: Typos, missing brackets, incorrect syntax. Your editor usually catches these.
**Logic Errors**: Code runs but produces wrong results. These are trickier - the code works, just not how you intended.
**Runtime Errors**: Code crashes while running. Null references, division by zero, file not found.
## Debugging Techniques
**Console Logging**: The simplest method. Add `console.log()` to see what values are at different points.
```javascript
console.log("User data:", user);
console.log("Before API call");
```
Works everywhere, requires no setup.
**Breakpoints**: Pause code execution at specific lines. Inspect variables, step through code line by line. Use browser DevTools or IDE debuggers.
**Rubber Duck Debugging**: Explain your code out loud (even to a rubber duck). Often you spot the bug while explaining.
**Binary Search**: Bug is somewhere in 100 lines? Comment out half. Still broken? Bug is in the remaining half. Repeat until found.
## Tools Every Developer Uses
**Browser DevTools**: Console shows errors, debugger lets you step through code, network tab shows API failures.
**IDE Debuggers**: VS Code, WebStorm have built-in debuggers. Set breakpoints, inspect variables, watch expressions.
**Error Tracking**: Sentry, Rollbar catch production errors and show stack traces. Know when users hit bugs before they report them.
## Real Debugging Example
Your form submission fails silently. No error message, nothing happens.
1. Check Console - see "Cannot read property name of undefined"
2. Set breakpoint before form submit
3. Step through code - discover user object is null
4. Trace back - API call failed but you did not handle the error
5. Add error handling - bug fixed
## Debugging Mindset
**Do not guess randomly**. Form a hypothesis, test it, learn from the result.
**Reproduce consistently**. If you cannot make the bug happen reliably, you cannot fix it.
**Simplify**. Strip away code until you find the minimum that reproduces the bug.
**Read error messages**. They usually tell you exactly what is wrong and where.
## Common Mistakes
**Changing multiple things at once**: You fix the bug but do not know which change did it.
**Not reading errors carefully**: The error message often contains the answer.
**Giving up too quickly**: Debugging is detective work. Persistence matters.
## Why Debugging Skills Matter
You will spend 30-50% of development time debugging. Getting good at it makes you dramatically more productive. The faster you find and fix bugs, the faster you ship features.
Senior developers are not necessarily better at writing bug-free code - they are better at finding and fixing bugs quickly when they inevitably appear.