Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What (function(){})(); mean? [duplicate]

Tags:

javascript

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.

like image 480
meotimdihia Avatar asked Apr 21 '26 09:04

meotimdihia


1 Answers

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
like image 168
Decko Avatar answered Apr 23 '26 22:04

Decko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!