Is this the correct way:
(function() {
// do something here
}());
Or this way:
(function() {
// do something here
})();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
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…