Lesson 11: Functions Recap ... Is this a glitch?


I've passed this lesson 2 different ways:

Here is the first:

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


When I do it this way, I pass the lesson, but the console prints [Function], which is of course, not "Hi, I am Shubanshii".

The second way I've passed the lesson is this:

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


My questions are:
1. With the first way, why is it printing [Function]?
2. Why does it say I passed when it prints out incorrectly?
3. Why does the second one print out correctly and not the first? I don't understand the difference between the two ways other than conciseness.

Thanks so much in advance,


With a little tweaking, you could use the first method:

output = nameString("Shubanshii");

the thing with return is, well, that it returns something, if gives you something back. The reason it prints function in your case is because you call the function again, but without () so javascript will tell you that it is a function.

Well, both pass because in both cases the correct things get returned, which seems to be what the exercise is checking.

I think the above also answers question 3


Ah, thank you so much for the swift reply. I'll remember the parentheses when calling functions from here on out.

I don't know if I follow the purpose or mechanism behind why it "tells me that it's a function" though. Is that important at this stage?


Well, you ask javascript to log something to the console, so because it is a invalid function call, it logs function, to tell you you tried to log a function, but didn't call it correctly.


Ahhhhhhhh, clears it right up. Thanks again dude.