(function () {
// do somethig
})();
What means this function in parentheses? ()();
Some developers creates functions like this in js files directly.
(function () {
// do somethig
})();
What means this function in parentheses? ()();
Some developers creates functions like this in js files directly.
What means this function in parentheses?
()();
That means a self-invoking function in JavaScript.
Notice to the: ();
- That is a calling.
Your function, which is anonymous BTW, will be invoked automatically without any caller intervention, but by itself, once it's declared.
In addition, as @Thilo suggested, it is also to get an isolated scope for local variables.
this is the self invoking anonymous function. This means the function within the first () parenthesis is the function which has no name and by next (); parenthesis you can understand that it is called at the time it is defined. And you can pass any argument in this second () parenthesis which will be grabbed in function which is in the first parenthesis. see this example:
(function(obj){
//do something with this obj
})(object);
here the 'object' you are passing will be accessible within the function by 'obj', as you are grabbing it in the function signature.