Version 1:
function myF() {
  var executed = false;
  return function() {
    if (!executed) {
      executed = true;
      document.getElementById("demo").innerHTML = "Ab"
    }
  };
};
myF();Version 2:
var myF = (function() {
  var executed = false;
  return function() {
    if (!executed) {
      executed = true;
      document.getElementById("demo").innerHTML = "Ab"
    }
  };
})();
myF();Why the v2 works, and why the v1 not? What's the main difference between these two, when they are called?
 
    