title: JS (function(){}) syntax
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/2897987/why-would-one-write-global-code-inside-a-function-definition-call-pair">Why would one write global code inside a function definition-call pair?</a><br>
    <a href="https://stackoverflow.com/questions/1639180/how-does-the-function-construct-work-and-why-do-people-use-it">How does the (function() {})() construct work and why do people use it?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm no JS ninja, and I'm now trying to learn the ins and outs of a language that has a lot more depth than I thought!</p>
  
  <p>I've seen a lot of code recently (jquery among them) that's coded like this:</p>
  
  <pre><code>(function(){
  var myLibrary = .....;
  window.myLibrary = myLibrary;
  })();
  </code></pre>
  
  <p>Can someone explain to me the benefit of this syntax?  What's the difference between that and just writing something like:</p>
  
  <pre><code>var myLibrary = {
  ...
  }
  </code></pre>