1)function () {
// code here...
}();
2)(function () {
// code here...
})();
3)(function () {
// code here...
}());
What are t
2 and 3 are exactly equivalent. There is no functional difference between them.
1 is a syntax error. Because the function is not wrapped in brackets, it is treated as a function declaration. It is invalid because function declaration need to be named. The brackets make it a "function expression"; these do not need to be named.