Possible Duplicate:
What does this “(function(){});”, a function inside brackets, mean in javascript ?
(function(){
    ---this code at here ----
})();
What does (function(){})(); mean? Please explain it to me.
Possible Duplicate:
What does this “(function(){});”, a function inside brackets, mean in javascript ?
(function(){
    ---this code at here ----
})();
What does (function(){})(); mean? Please explain it to me.
 
    
     
    
    It makes an anonymous function and executes it. You use it to prevent variables from poluting the global scope.
(function(){
  var test = "Hello";
})();
alert(test); //test will be undefined here
 
    
    The function is immediately executed after parsing it.
 
    
    Well, you use a function expression as a closure which gets executed immediately and 'this code at here' will not pollute global namespace.
