Help with (4.) How does a function work?


I'm not sure why undefined is popping up after this everytime.

var foodDemand = function(food)
console.log("I want to eat"+" " + food);

console.log(foodDemand("a lot of that and maybe the cat in the hat!"))


That is a normal response from the console when a function has no return value. It can be ignored in most cases. Sometimes it does indicate a small error on our part, though.


console.log() has no return statement. If we log the return from this method, we will see,

console.log(console.log(''));    // undefined

Instead of logging your function call, just write the call on its own.

foodDemand("green eggs and ham");

// I want to eat green eggs and ham


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.