Question

I have just started using JQuery but it doesn't write any error when trying to access an unexisting variable, for example:

window.alert($.ui.keyCode.someNonExistingName);
switch(e.keyCode) {
    case $.ui.keyCode.someNonExistingName:
        ...
        break;
    ...
}
someNonExistingFunction();

will pop a window with ("Undefined") text in it, but no error will be writen into console. On the other hand, when it tries to call an undefined function, error is printed into console and the program is stopped.

Is there any way to set error level reporting to report all errors and warning, such as usage of undefined variables?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top