The difference between closures with parentheses inside and out

Can someone explain what the difference is between these closures? Is there any difference? I have not seen the second example before (parentheses inside).

(function(a, b) {
    //...
})(x, y);

// Parentheses inside
(function(a, b) {
    //...
}(x, y));

And here, is there any difference between these closures? Is there a scenario where there will be a difference?

FOO.Bar = (function() {
    //...
})();

FOO.Bar = (function() {
    //...
}());
+4
source share
1 answer

No. In both cases they are the same.

What happens when you end your function in parentheses is what happens from the declaration of the function to the expression of the function, which can be called immediately.

If you call it in parentheses or after that it doesn't matter. A "conflict" has occurred, and you can cause it.

And actually you can do it

FOO.Bar = function () {
    return 123;
}();

, Bar FOO.

+1

All Articles