Is this the correct way:
(function() {
// do something here
}());
Or this way:
(function() {
// do something here
})();
It's only a difference in style, both are "correct." I prefer the second and would venture that it's more popular, some prefer the first.
What you can't do is simply
function() {
// ...this example is wrong and won't work
}();
You need the parentheses in order to put the parser in the right mode that you're doing a function expression rather than a function declaration, but it doesn't matter whether the invoking parens at the end are within the main parens or outside them. You can try it with this live copy with the JavaScript engines in your favorite browsers...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With