Parentheses in an assignment like this:
var k = myfunction();
mean that what's being assigned to k is not the function itself, but rather the result of calling the function — the function's return value, in other words.
Without the parentheses, then you are indeed assigning a reference to a function to some variable:
var f = myfunction;
After doing that, it'll be possible to call the function by either name:
f(); // same as myfunction();
Functions in JavaScript are just a special type of object, but they really are just objects in most ways. They can have properties, and references to them can be passed around exactly in the same way one passes around references to objects.
What makes a function special is that you can call it. A reference to a function followed by () (or () with arguments) is a function call no matter where that reference came from. That's why an assignment of a function call to a variable, or passing a function reference as an argument in a call to some other function, is useful.
Parentheses in an assignment like this:
var k = myfunction();
mean that what's being assigned to k is not the function itself, but rather the result of calling the function — the function's return value, in other words.
Without the parentheses, then you are indeed assigning a reference to a function to some variable:
var f = myfunction;
After doing that, it'll be possible to call the function by either name:
f(); // same as myfunction();
Parentheses in an assignment like this:
var k = myfunction();
mean that what's being assigned to k is not the function itself, but rather the result of calling the function — the function's return value, in other words.
Without the parentheses, then you are indeed assigning a reference to a function to some variable:
var f = myfunction;
After doing that, it'll be possible to call the function by either name:
f(); // same as myfunction();
Functions in JavaScript are just a special type of object, but they really are just objects in most ways. They can have properties, and references to them can be passed around exactly in the same way one passes around references to objects.
What makes a function special is that you can call it. A reference to a function followed by () (or () with arguments) is a function call no matter where that reference came from. That's why an assignment of a function call to a variable, or passing a function reference as an argument in a call to some other function, is useful.
Parentheses in an assignment like this:
var k = myfunction();
mean that what's being assigned to k is not the function itself, but rather the result of calling the function — the function's return value, in other words.
Without the parentheses, then you are indeed assigning a reference to a function to some variable:
var f = myfunction;
After doing that, it'll be possible to call the function by either name:
f(); // same as myfunction();