Question on closure example from eloquent javascript

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?

1 Like

There really isn’t any difference. The first function shows that you still have access to the variables inside of wrapValue function even it’s returned.

But in the end, they do the same thing.