11. Functions recap


The console.log reads [Function], how is that?
It supposed to be correct because I can proceed, but ofcourse it's not.




you call the function, to log what the function returns you should use console.log here

this code:

console.log (nameString);

is another function call, but because its without parentheses, JavaScript tells you its a function


So console.log is printing "function" because it's telling you what nameString is. Place your name inside what you're looking to print out with console.log. Hope this helps.

var nameString = function (name) {
    return ("Hi, I am" + " " + name);



But if he has already passed the function his name, why does he need to print it out again in order for it to work? Feels weird and clunky to me.


My Code is:-
var nameString = function (name ) {
return ("Hi, I am" + " "+ name);
console.log (nameString);

Output is:-
[Function: nameString]
My question is that - Why I can't see the output "Hi, I am SONU". Explain!


here you call the function:


to log to the console what the function returns, you should pass this as argument to console.log:


the line below you call the function without parentheses, then JS tells you this is a function


I am getting you now what u want to say:wink:


Why would it be this way? console.log(nameString("Andrew"));

So far in the course we have always first called the function independently. For example, in Lesson 4 we print the result as part of the function and define food outside of the function.
For example:
var foodDemand = function(food) {
console.log("I want to eat" + " " + food);

How are new coders expected to know how to define a function and print it in the same line? Introducing a new concept like this near the end of a unit seems antithetical to quality instruction.


to log what the function returns.