The main reasons I've found for that type of message are:
You misspelled the name of the variable either when you defined it or when you reference it. Remember JS is case-sensitive.
The variable is out of scope. You may have defined it in one function and tried to reference it in another. Define it outside of any functions to solve this problem.
You are trying to use a property or method that is undefined, or the object reference is undefined.
Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.