There is a piece of code :
(function aaa(){alert("555")})()
and this :
(function aaa(){alert("555")}())
What is the difference?
There is a piece of code :
(function aaa(){alert("555")})()
and this :
(function aaa(){alert("555")}())
What is the difference?
If you put the first one together twice, it only runs the first one before producing a TypeError
:
(function aaa(){alert("555")})()(function aaa(){alert("555")})()
If you put the second one together twice, it runs both of them before producing a TypeError
:
(function aaa(){alert("555")}())(function aaa(){alert("555")}())
In short, they're two different style choices for scoping code to avoid cluttering the global namespace, but the second one in my experience tends to be favored more since it's less prone to erroring when multiple scopes are concatenated together. It's best to always begin the scope with a semicolon to ensure that it executes when concatenated like so:
;(function aaa(){alert("555")}());(function aaa(){alert("555")}())