Debugging Tips
Debugging methods, common errors, breakpoint types, tools. Fix bugs faster with systematic approach.
Debugging Methods
Print Debugging: console.log, print statements
When: Quick, simple debugging
Debugger: Breakpoints, step through code
When: Complex logic, variables
Logging: Structured logs, levels
When: Production, monitoring
Unit Tests: Isolated function testing
When: Prevent bugs, verify fix
Rubber Duck: Explain code step by step
When: Logic errors, fresh perspective
Code Review: Fresh eyes on problem
When: Hidden bugs, overlooked issues
Common Errors & Fixes
Null reference: Undefined/null value
Fix: Check before access, use optional chaining
Type mismatch: Wrong type passed
Fix: Type checking, TypeScript
Off-by-one: Index/loop bounds
Fix: Check boundaries, test edge cases
Race condition: Async timing
Fix: Await, locks, proper sequencing
Memory leak: Unreleased resources
Fix: Clean up listeners, references
Infinite loop: Wrong condition
Fix: Check loop logic, add limits
Breakpoint Types
Line: Pause at specific line
Conditional: Pause when condition true
Exception: Pause on error/throw
Function: Pause when function called
Logpoint: Log without pausing
Debugging Tools
VS Code Debugger: Built-in, F5 to start
Chrome DevTools: Browser JS debugging
Node.js Debugger: node --inspect flag
Python pdb: import pdb, pdb.set_trace()
GDB: C/C++ debugging
Xdebug: PHP debugging
Debugging Tips
Reproduce bug first
Isolate the problem
Check recent changes
Read error messages
Check stack trace
Verify assumptions
Test edge cases
Use version control
Take breaks
Ask for help
VS Code Debugging Shortcuts
F5: Start debugging
F9: Toggle breakpoint
F10: Step over
F11: Step into
Shift+F11: Step out
Ctrl+Shift+F5: Restart
F9: Toggle breakpoint
F10: Step over
F11: Step into
Shift+F11: Step out
Ctrl+Shift+F5: Restart
Systematic Approach
1. Understand problem (what, when, where). 2. Reproduce reliably. 3. Isolate component. 4. Hypothesize cause. 5. Test hypothesis. 6. Fix root cause (not symptom). 7. Verify fix. 8. Add test to prevent recurrence. 9. Document for future. Don't rush - systematic faster than random.