How to troubleshoot your code?

  1. Typos
  2. Syntax
  3. General logic flow

At times I might catch an error with VSCODE, at times I have no idea what the error means, and at times the Google console gives me no errors and the code still doesn’t work.

How do you go about catching errors?.. for me, the big points are TYPOS, SYNTAX, and General logic flow, yes, in that same order.

Usually, before coding I think of a logic flow first, then look for pieces of codes to connect… at times works good, but many times I end up with typos, bad syntax, or a logic flow that might not be the best approach…

What do you do to troubleshoot your code???

Experience is the only way to get better at debugging code. That, and knowing your tools.

You can get some help from:

  1. Your editor. Learn what the syntax highlighting is telling you.

  2. Formatters (like prettier). They will break on syntax errors when you format and tell you where it broke. Also, well-formatted code just makes it easier to spot errors.

  3. Code linters (like ESLint). Static code analysis mainly helps with bad practices (breaking rules). But they will also complain about things that are from mistakes (like typos).

  4. Spellcheckers made for code editors.

  5. The debugger (in whatever runtime) and console logs.

  6. The browser has a lot of developer tools built-in. Just having the console open when coding can be a big help. Learn to read the error messages and understand them.

Try and start at the simplest reason you can think of and work your way up in complexity. It is very easy to miss simple mistakes if you do not account for them from the get-go. Log out everything and check your assumptions. They are often wrong.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.