Are they the same?
var multiply = function () {
//..
}();
var multiply1 = (function () {
//..
}());
asked Jul 9, 2011 at 16:12
johnny
1,2611 gold badge17 silver badges32 bronze badges
3 Answers 3
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.
answered Jul 9, 2011 at 16:32
nicosantangelo
13.8k3 gold badges35 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
mqp
I like this answer, agree with the article, and now I will start writing my function invocations with parens around them. Thanks!
user123444555621
...and also the same as
(function () {...})(), which I prefer.Yes, they are totally identical.
answered Jul 9, 2011 at 16:14
mqp
72.3k15 gold badges99 silver badges124 bronze badges
Comments
They seem to work the same here in Chrome: http://jsfiddle.net/jfriend00/G5DZp/
answered Jul 9, 2011 at 16:18
jfriend00
711k104 gold badges1.1k silver badges1k bronze badges
Comments
lang-js
(function() { })()andfunction() {}()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.(function(){}())over(function(){})()- just a matter of taste