Let's take it in order. In JavaScript, a function is a first-class object . You can perform various actions with it.
Can save function to variable
var f = function() { // ... };
You can pass a function to a function as an argument:
function runner(task) { task('foo bar baz'); }
You can return the function from the function as a result:
function builder() { return function() { // ... } }
You can create a function at runtime:
var f; if (Math.random() > 0.5) { f = function() { console.log('low'); }; } else { f = function() { console.log('high'); }; }
And, unlike other objects of the first class, the function can be called. To do this, there is a special syntax () (parentheses):
var f = function() {/* ... */} // Вот так функция вызывается f();
Now back to your question. Right here:
function foodDemand (food) { console.log("I want to eat" + " " + food); }
You declare a function that is accessible by the foodDemand .
Speaking
I do not call the function, but simply assign it to a variable a.
You're wrong. You just call the function and assign the result of its execution to the variable a .
The assignment of the function to the variable a must be of the form:
// Обратите внимание на отсутствие круглых скобок. var a = foodDemand;