I have seen various code which is implemented in following two way. I always use the second one (2.). I wanted to know two thing here.
(function () {
//some code here, angular code
})();
(function () {
//some code here, angular code
});
Yes, you are not executing the second one.
In the first example, you are declaring an anonymous function, which gets run afterwards with no parameters.
In the second example, you are just declaring it, but not running it.
()
is what makes it run, in this case by passing it no parameters.
Edit:
As @Osman has just pointed in the comments, the first one is known as IIFE.
This pattern is so common, a few years ago the community agreed on a term for it: IIFE, which stands for Immediately Invoked Function Expression.