Sometimes, your browser will give you an error so unspecific, you’ll want to throw tomatoes at it. For example: “TypeError: Undefined is not a function”. This happened to me the other day while working on an exercism.
No matter what I did, it seemed like the error stayed the same and my frustration level grew. And tools like repl.it and JS Hint weren’t helpful; they just gave me the same error as the console with no explanation.
A few days later, I’ve now fixed my code and wanted to post some lessons learned for those in a similar situation, because If you’ve already ruled out everything you know, blanket errors like this one may need their own debugging process. Here are a few steps to get you started:
1. What did you last work on?
If your code was working 5 minutes ago, you are the culprit. Try undoing or going back to an earlier git version.
You’re going to have to pull your code down to the smallest building blocks so that you can examine each piece and see where the code is going wrong. You can test smaller code chunks individually in repl.it, using repl’s console to plug in variables.
If you’re working with a number of interdependent functions, it’s likely that one of your functions or variables is simply defined too far down in your code, causing the browser to throw an “undefined” error. Look through and make sure each variable, function, script is defined before it is called.