var myObject = (function(){
var value = 0;
return {
getValue: function(){
return value;
}
}
}());
var myObject = (function(){
var value = 0;
return {
getValue: function(){
return value;
}
}
})();
The execution seems to return the same Object. i.e., myObject contains
{{
getValue: function(){
return value;
}
}}
in both the cases.
I know something like (function(){})()
executes because (function(){})
is an expression which returns a function and the trailing ()
executed the function being returned.
But why does this execute (function(){}())
? I was expecting a syntax error here.