1Check your premises
The hardest bugs to fix are the ones where your underlying assumption is wrong. 'The API is definitely returning an Array' — you spend 3 hours debugging React. Finally, you check the Network tab, and the API is returning an Object. NEVER assume. Verify every step of the data pipeline.
2Step-by-Step Breakdown
The Panic. A junior sees a red error wall, panics, and immediately pastes it into ChatGPT. A mid-level developer reads the error, identifies the line number, and forms a hypothesis.
The Scientific Method. Debugging is science. 1) Observe the bug. 2) Form a hypothesis ('I think the variable is null'). 3) Create an experiment (console.log). 4) Analyze results. 5) Repeat.
Divide and Conquer. If a 500-line function is failing, don't read all 500 lines. Put a console.log at line 250. Is the data correct there? If yes, the bug is in the bottom half. You just eliminated 50% of the code.
Rubber Ducking. Explain the broken code, line by line, out loud to an inanimate object (like a rubber duck). In the process of forcing your brain to translate code into spoken logic, you will often spot the flaw.
Knowledge Check. What is the core principle of 'Divide and Conquer' (Binary Search) debugging?
- →Isolating the issue by repeatedly cutting the problematic area of code in half
- →Dividing the problem among the team so everyone searches StackOverflow
The Chrome Debugger. Console.log is great, but mid-levels use the Debugger. Setting breakpoints allows you to pause the execution of the code and inspect the value of every variable in memory in real-time.
Isolate the Environment. Is the bug in your code, the library, or the browser? Build a minimal reproduction case in CodeSandbox. If it breaks there, it's the library. If it works there, it's your specific setup.
Reading the Source. When the documentation fails you, go to GitHub and read the library's actual source code. It is the ultimate source of truth. Don't treat libraries as black magic boxes.
Knowing When to Ask. The 30-minute rule. If you are stuck for 30 minutes and making ZERO progress, you must ask a senior for help. Do not spin your wheels for 3 days to save your ego.
Summary. You are not a coder. You are a problem solver who happens to use code.
