The common practise for creating modules is to wrap them in parens so you won\'t leak any variables outside of the module (when concatenating etc).
There is also
Well, many JavaScript programmers think void
is confusing and redundant, especially Douglas Crockford who calls it one of the "Bad Parts" of JavaScript.
Preceding a function definition with void
can be especially confusing. In languages like C++, it means "This is a type of function that doesn't return a value." In JavaScript, void
doesn't define anything; instead it evaluates the function (or other expression) and returns the value undefined
. So you don't see it much in JavaScript code.
For more info on using !
to precede modules, check out this StackOverflow answer.
Also make sure to read Ben Allman's original blog post on IIFE's.