I will start out by saying, I am a junior developer, so 85% of the time... I am the bug. I have however developed some tips and tricks along the way that have helped pinpointing my bugs as well as in writing cleaner and dryer code.
Start by writing clearly planned and tested code:
This may seem like a no brainer but the process of "sharpening the axe before cutting down the tree" really, really helps in the debugging process. Before I code at all or even write a README.md I start by asking myself 3 questions and writing them out in Evernote (for searchability later on).
- What am I trying to code and/or what is the bug that I am trying to solve? What do I already know about said code?
- What questions do I have/things do I not know?
- Answers to those questions as I find them. I then begin to make my README.md, user stories, and diagrams (if not already existing). When I have a pretty clearly documented plan I begin to write or modify tests. Often once I solve or find a bug, I will come back and modify or update tests and documentation.
Check for esLint errors or highlighted/non highlighted code in VS Code. It is always worth taking the time to set up esLint for a project.
Check variables and spelling check syntax.
Dev Tools: I really love Chrome Dev tools. I think it is worth it though to test code in multiple browsers.
- Check the console for errors: is the error obvious?
- Reproduce the error if semantic (enter data into a form etc.)
Comment out code in and error message to help locate an error using comment tags. Once you pinpoint the error look at syntax, spelling, and functionality.
Sources tab -> Event listener breakpoints -> step into , step over, step out of... etc.
- Pause code at other break points
If trouble shooting an API request... checkout the Network tab to see the amount of requests be sent and what is being received.
There are also numerous different language specific debugging tools that come in very handy during coding and debugging but these steps are a great start. What tips do you use and when do you crack and ask for another set of eyes? Thanks for reading!