I would like to create an anonymous function and then call it immediately.
1) This will result in a syntax error. Why?
function ()
{
alert("hello");
}();
2) complete the function definition with () and it works.
(function ()
{
alert("hello");
})();
3) or assign an anonymous function to a variable. He works.
var dummy = function()
{
alert("hello");
}();
Why does the first method not work?
source
share