Why jsHint doesn't detect an error “is undefined”?-Collection of common programming errors

I tried to use jsHint on my project. But for me it doesn’t work obviously. For example:

(function () {
    if (!window.myApp) window.myApp = {};
    var myApp = window.myApp;
    var a = function (key) {
        key = key || "key";
        return myApp.someModule.get(key);
    };

    a();
})();

This chunk should throw error, something like that: “TypeError: myApp.someModule is undefined”, but jsHint is still silent. I use default settings for jsHint from http://jshint.com/ . Can anybody help me? Thanks a lot.

  1. Fairly sure that it only checks for variables in the “local” scope, it won’t check all the way down objects chains. In fact I’d say it’s impossible to be able to detect in all cases.

    Consider:

    var o = {};
    someAjaxRequest({
        callback: function(response) { 
            o[response.responseText] = 'found!';
        }
    });
    

Originally posted 2013-11-09 21:09:12.