Code1:
var x=(function(){
return {
greet:function(){
alert('Hello from code1');
}
};
})();
Code2:
var x=function(){
return {
greet:function(){
alert('Hello from code2');
}
};
}();
Both will be invoked like:
x.greet();
In the style 1 I've enclosed the self executing function within parenthesis while in the second code it is not. Both work same. So what is the difference between code1 and code2 and which is remanded way?