AlexStack
AlexStack

Reputation: 17381

what does it do? (function(){...}());

I was reading facebook javascript SDK when I saw the following syntaxt that I don't understand: (function(){...}()); Does anyone know what does it do?

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: 'your app id', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

Upvotes: 3

Views: 226

Answers (1)

knittl
knittl

Reputation: 265151

it's an anonymous function, that gets called immediately after its declaration. It's used to create local variables without clobbering up the global scope. the variable e will not be visible nor accessible outside the function block

Upvotes: 11

Related Questions