title: Javascript Anonymous Closure
body: <p>I have read a lot about closures in Javascript
  What are those braces for??
  I read on <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Closures">mozilla.org</a> which says closure should be defined as </p>
  
  <p><code>(function(){...})();</code></p>
  
  <p>but on <a href="http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html">http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html</a>, it says the closure function is</p>
  
  <p><code>(function(){...}());</code></p>
  
  <p>What's the difference or the latter one is wrong?
  what's the purpose of the last ()? Would you put some parameters inside?
  I am looking for a good reference.</p>
  
  <p>Edit:
  Moreover, there is an example on <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Closures">Mozilla.org</a></p>
  
  <pre><code>var makeCounter = function() {
  var privateCounter = 0;
    function changeBy(val) {
      privateCounter += val;
    }
    return {
      increment: function() {
        changeBy(1);
      },
      decrement: function() {
        changeBy(-1);
      },
      value: function() {
        return privateCounter;
      }
    }  
  };
  </code></pre>
  
  <p>why the semicolon is needed for this 'function'? If it needs to be invoked immediately after its declaration, a () should be put before the ending semicolon. But there is not.</p>