In JavaScript, functions are objects too, and by applying the () operator to it, you will invoke the function and the invocation will evaluate to the result returned from the function.
As such, let's break down your statement, which is:
var myFunct = function() {
alert("here");
}();
First, you define a function, so let's "refactor" this so that part becomes clearer.
var myFunctionDeclaration = function() {
alert("here");
};
var myFunct = myFunctionDeclaration();
Now, it should be easier to see that you're invoking the function in your code.
Function declarations aren't statements that need to be by themselves, but can be used as expressions that return the function object.
So basically your code was this:
var myFunct = (expression that produces function object)();
^^
+--- invoke the function
This means that you can chain this together. If your function returns another function, you can call this new function as well, in the same statement.
For instance:
var myFunct = function() {
alert("here");
return function() {
return 10;
};
}()();
^ ^
| +-- calls the inner function, that was returned when calling the outer
| function
|
+---- calls the outer function, which returns a new function object
// myFunct ends up being 10