Short answer: It doesnβt matter if you put them there.
Long answer: It doesnβt matter, because only what they are is important for JavaScript. The reason for this is because the language specification determines that an operator should start with the function keyword if you declare a named function. Therefore, it is contrary to the specification to define IIFE like this:
function () {}();
The workaround for this is to wrap the whole thing in parentheses so that the statement no longer starts with the keyword function . You achieve this using
(function () {})();
as well as using:
(function () {}());
Which one you choose is completely arbitrary and therefore up to you.
I (personally) put parentheses around a function, not around a call, for example:
(function () {})();
Cause. I want to use the smallest part of the code, which will be wrapped up in what is required only for technical reasons, and this is a function definition, not a call. In addition, the specification says that you cannot define a function in this way; it is not a function call. Therefore, I find this more clear if you complete the definition, not the call.
Golo roden
source share