I\'m a javascript newbie trying to wrap my mind around this code. I got it here http://brackets.clementng.me/post/24150213014/example-of-a-javascript-closure-settimeout-inside>
The parantheses are optional in your example of an immediately invoked function.
(function() {
// some code
})();
Can be re-written as
function() {
// some code
}();
So the i
in the example function's call becomes the x
in the function definition.
function(x) { // x = 1
return function() {
console.log(x); // x = 1
};
}(1)