Explanation:
const myFunction1 = function() {
let executed = false;
return function() {
if (!executed) {
executed = true;
document.getElementById("demo").innerHTML = "Ab"
}
};
};
myFunction1();
Example 2:
const myFunction2 = (function() {
let executed = false;
return function() {
if (!executed) {
executed = true;
document.getElementById("demo").innerHTML = "Ab"
}
};
})();
myFunction2();
What makes the second version work, while the first one doesn't? Explore the main difference in how these two are structured and called.