I often write my JS self executing anonymous functions like this
(function(){})()
but the other day I saw this, in somebody's code
(function(){}())
what's the difference, and is one recommended over the other?
I often write my JS self executing anonymous functions like this
(function(){})()
but the other day I saw this, in somebody's code
(function(){}())
what's the difference, and is one recommended over the other?
I recommended this one, because it makes more sense.
You have your function
function(){}then you append the()to execute it, then you wrap the whole thing in()to specify that it's an expression. That is done so the js interpreter will not define it as a function declarations, but as a function expression.But it doesn't matter, it will execute properly, so it's a personal taste problem.