Practically speaking, what is the difference between this function (from Eloquent Javascript)
function wrapValue(n) {
var localVariable = n;
return function() {return localVariable;};
}
and this simpler function:
function wrapValue2(n) {
return function() {return n;};
}
I understand that the first function is a closure and the second it not. Presumably the first function actually looks up what value is stored in the identifier localVariable and then returns that.
But what practical difference does this make? Presumably the function returned by wrapValue2 would be faster? Is there anything I can do with the first function that I can’t do with the second function? For instance, I can’t actually access this localVariable via it’s identifier in any way, right?