title: What's the difference between these two function declarations?
body: <p>Version 1:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myF() {
    var executed = false;
    return function() {
      if (!executed) {
        executed = true;
        document.getElementById("demo").innerHTML = "Ab"
      }
    };
  };
  
  myF();</code></pre>
  </div>
  </div>
  </p>
  
  <p>Version 2:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myF = (function() {
    var executed = false;
    return function() {
      if (!executed) {
        executed = true;
        document.getElementById("demo").innerHTML = "Ab"
      }
    };
  })();
  
  myF();</code></pre>
  </div>
  </div>
  </p>
  
  <p>Why the v2 works, and why the v1 not? What's the main difference between these two, when they are called?</p>