5

Are they the same?

var multiply = function () {
      //..
      }();

var multiply1 = (function () {
      //..
      }());
2
  • 1
    johnny - note that (function() { })() and function() {}() can be different depending on the context - if not assigned to a variable, the latter will be interpreted as a statement (and a syntax error) rather than an expression. Commented Jul 9, 2011 at 16:33
  • 1
    Some people prefer (function(){}()) over (function(){})() - just a matter of taste Commented Jul 9, 2011 at 18:10

3 Answers 3

9

As mquander said in that case they are the same, but if you want to read a little more about it you can go to: An Important Pair of Parens.

Sign up to request clarification or add additional context in comments.

2 Comments

I like this answer, agree with the article, and now I will start writing my function invocations with parens around them. Thanks!
...and also the same as (function () {...})(), which I prefer.
4

Yes, they are totally identical.

Comments

2

They seem to work the same here in Chrome: http://jsfiddle.net/jfriend00/G5DZp/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.