I'm working through examples in the ebook "eloquent javascript." On page 51, in the Functions chapter, in the Closure section, there's the following example:
function wrapValue2(n) {
var localVariable = n;
return function() {
return localVariable;
};
}
var wrap2 = wrapValue2(3);
console.log(wrap2());
As you can see in the last line of the code above, "console.log(wrap2());," the variable is being called inside of console.log. I was having some trouble re-writing this code until I realized there are parenthesis after the variable! Why would I put parenthesis after a variable?
Don't I only do that after a function?
Is this command using the variable as a function? If so, why?
Is it because the object contained within the variable is a function? That doesn't seem very likely.
Thanks in advance!