javascript - how to avoid Uncaught ReferenceError

ID : 274335

viewed : 41

Tags : javascriptnode.jsjavascript





Top 2 Answer for javascript - how to avoid Uncaught ReferenceError

vote vote

96

Test typeof module !== "undefined" instead of module

why doesn't the browser treat the variable module as undefined and not throw any error?

Because, as well as being undefined, it is also undeclared. This is an excellent feature for throwing an error when you make a typo in a variable name. For example, it is better for the following to error instead of being treated as false:

var loose = true; if (lose) { } 
vote vote

86

Top 3 video Explaining javascript - how to avoid Uncaught ReferenceError







Related QUESTION?