5 Awesome Tips for debugging your code

Kinanee Samson - Feb 19 '21 - - Dev Community

I stumbled across some pictures that made me cringe with laughter, debugging our code is something that we can't run from no matter how much we loath it, so i came up with this useful tips i employ whenever I'm debugging my code.
Alt Text

Console.log is your friend

I cannot understate the importance of the console object especially the log method, they are your first weapon of defense when it comes to debugging your code, if something is behaving strange the first thing i do is to log it to the console. This provides some useful information about the error and stuff, if we are observant enough, we can build custom error handler based on the information obtained from the console, so next time there is a bug do not hesitate to log that error out to the console.

Stackoverflow should be close

Stack overflow was created for helping us, developers with errors in our code so you shouldn't be hesitant in posting up your error and code base to stackoveflow, personally if the console.log method doesn't provide me with a clue to handling the bug, i head over to stackoverflow and 90% of the time i am not disappointed, and i believe that you won't be so make that a habit.

Alt Text

Google it.

If stackoverflow doesn't get you something then you should definitely google your problem, actually you should google your problem first before heading to stackoverflow, there's a reason why google is the most popular search engine and using google doesn't make you anymore less of a developer, in fact it actually makes you a top developer

Typos hide in plain sight

A bug can make you curse and swear for no reason and little wonder it was just a typo, so next time you have an error in your code ensure that you cross check spelling and variable names. One thing with typos is that it will hardly occur to you that it is actually a typo so do spend some time going over certain spelling before you curse the hell out of the bug.

Alt Text

Let it be

if you have actually tried all these things and none of it works, the best thing is just to take a break and go and do something else, other than coding. Allow your brain to settle, take some rest say 3-6hrs depending on the time available to you and then when you feel fresh again, come back and have a go at it again.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .