I’m studying closures and the global scope, and am confused about when to use }()) vs. })(). It seems that I’ve lucked upon a situation where it doesn’t matter which one I use.
(function() {
var myFunction = (function() {
var i=100;
return function() {
return i++;
}
}());
var X = myFunction();
console.log(X);
X = myFunction();
console.log(X);
})();
(function () { return 1; });doesn’t evaluate the function.("append" + " us")does evaluate the strings.So yeah, in this case it doesn’t matter because:
evaluates to
(function() { return i++; }which just returns the anonymous function.and:
evaluates myFunction after the braces. And.. just returns the anonymous function. Woh.