{"id":632,"date":"2022-08-30T15:04:35","date_gmt":"2022-08-30T15:04:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/why-jshint-doesnt-detect-an-error-is-undefined-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:04:35","modified_gmt":"2022-08-30T15:04:35","slug":"why-jshint-doesnt-detect-an-error-is-undefined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/why-jshint-doesnt-detect-an-error-is-undefined-collection-of-common-programming-errors\/","title":{"rendered":"Why jsHint doesn&#39;t detect an error &ldquo;is undefined&rdquo;?-Collection of common programming errors"},"content":{"rendered":"<p>I tried to use jsHint on my project. But for me it doesn&#8217;t work obviously. For example:<\/p>\n<pre><code>(function () {\n    if (!window.myApp) window.myApp = {};\n    var myApp = window.myApp;\n    var a = function (key) {\n        key = key || \"key\";\n        return myApp.someModule.get(key);\n    };\n\n    a();\n})();\n<\/code><\/pre>\n<p>This chunk should throw error, something like that: &#8220;TypeError: myApp.someModule is undefined&#8221;, but jsHint is still silent. I use default settings for jsHint from http:\/\/jshint.com\/ . Can anybody help me? Thanks a lot.<\/p>\n<ol>\n<li>\n<p>Fairly sure that it only checks for variables in the &#8220;local&#8221; scope, it won&#8217;t check all the way down objects chains. In fact I&#8217;d say it&#8217;s impossible to be able to detect in all cases.<\/p>\n<p>Consider:<\/p>\n<pre><code>var o = {};\nsomeAjaxRequest({\n    callback: function(response) { \n        o[response.responseText] = 'found!';\n    }\n});\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:09:12. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I tried to use jsHint on my project. But for me it doesn&#8217;t work obviously. For example: (function () { if (!window.myApp) window.myApp = {}; var myApp = window.myApp; var a = function (key) { key = key || &#8220;key&#8221;; return myApp.someModule.get(key); }; a(); })(); This chunk should throw error, something like that: &#8220;TypeError: myApp.someModule [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-632","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=632"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/632\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}