Please see my comment to the question.
Of course,
wrap1
is a variable, but it means nothing. A variable can be a function or non-function. Function is also on object. Let's see.
var wrap1 = wrapValue(5);
means that
wrap1
is assigned to some object returned by function
wrapValue
. So, let's see what this function returns. As you can see, it returns another function. In other words, returned object is a function function object. Unlike other objects, this kind of object supports the operation "call". And the syntax
wrap1()
is just the syntax call.
The question "why no just wrap1?" simply makes no sense. Both wrap1 and wrap1() are two different expressions; both are correct and return totally different objects: first return the result of the function call, the type if this result is defined by
n
passed during the call to
wrapValue
; second returns a parameterless function function object which, in turn, can return the object of the same type. Compare
var myObject = wrap1;
var myOtherObject = wrap1();
var someObject = myObject();
Are you getting the idea?
—SA