What is the difference between these two:
(function () {
alert('something');
})(); # invocation parens after the wrapping parens
and
(function () {
alert('something');
}()); # invocation parens inside the wrapping parens
—both give me the same result: alerting “something”.
There is no difference. Both will do exactly the same thing (invoke the anonymous function expression).
The parentheses around the anonymous function are simply there to ensure the function is parsed as an expression rather than a declaration (which is important because a declaration can’t be invoked). You may also see other operators used to the same effect. For example:
Note that if you use a static analysis tool like JSLint it may complain about the first form in your question (with the invoking parentheses outside the grouping operator). The reason for this is that some people consider the second form easier to understand.