Using ES5 Strict Mode
A small but precious addition to all the Module Patterns that use IIFEs as their basic building blocks, is the use of Strict Mode for JavaScript execution. This was standardized in the fifth edition of JavaScript, and is an opt-in execution mode with slightly different semantics, in order to prevent some of the common pitfalls of JavaScript, but also having backwards compatibility in mind.
Under this mode, the JavaScript runtime engine will prevent you from accidentally creating a global variable and polluting the Global Namespace. Even in not-so-large applications, it is quite possible that a var
declaration before the initial assignment of a variable can be missing, automatically promoting that to a global variable. To prevent this case, strict mode throws an error in case an assignment is issued to an undeclared variable. The following image show the error that is thrown by Firefox and Chrome when a Strict Mode violation happens.
This mode can be enabled by adding...