Do you know that uneasy feeling when you're debugging and just trying stuff out without a plan aka programming by accident?
use that uneasy feeling as a trigger to stop and make a plan. Debugging a bug is often complicated and sometimes a large effort. Don't always aim to fix it in one go. Make intermediate goals that will help you solve the bug. Some ideas to think about:
reduce your search area:
- remove code without making the bug disappear
- use git bisect (google for more info)
- reduce the size of the data you're working with (less data to sift through when console logging)
increase visibility:
- render data to your UI. JSON.stringify is your friend. Don't restain yourself to the console.log
- Use a debugger and understand the runtime behaviour of your program!
My process when debugging a hard bug is:
- create a list of hypotheses that could cause the bug
- remove all causes from the list that violate known facts/datapoints
- determine what data points you need to collect next to remove additional hypotheses from list 1)
- repeat 2) and 3) until you have 1 hypothesis left
- prove the remaining hypothesis
- fix bug