Using an undefined variable is not an error, but accessing a property or method on an undefined variable is. There is no way to trap this as it is not actually an error, just how javascript works.
However, many modern javascript IDEs will underline text for you if it knows that the variable doesn't seem to be defined anywhere. For instance, I use WebStorm (http://www.jetbrains.com/webstorm/) which does this automatically for me, but this is a common feature.