Can Someone Help With Functions - Return and Logging to Console?


Hi There,

I am extremely confused why this is correct:

I feel like I am doing something wrong, can someone explain? Thank you for your time.



Actually the nameString("Aaron") line is the reason this passed the line below is not needed.
@boardmaster76568 What happens when you call nameString is that you enter the function assign your argument ("Aaron") to the function's parameter (name), compute the value after return ("Hi, I am Aaron") and then send this value back to the function call. So that the function call could be used as this value. As you can see in your code this value goes unused, if it would be the last statement you could see an echo on the screen but as it is not you need console.log around the value to print and see it.

About this statement:
and the mysterious [Function]: Well you printed the value of the variable nameString here and as you assigned a function to it here:

var nameString = function ...

it tells you that this is a function. As said the more interesting case would be to call the function to get the value printed. Hope this make some sense.

Why we create function using a var (variable)? why we cant make function without using var tag?

Hi there,

Thanks for your reply. Unfortunately, I'm still not sure what the right answer is. This said that I passed, and could move on, but I don't feel comfortable accepting that and doing so if it's not right. If console.log(nameString); isn't correct, what is?

Thanks for any further explanation.




nameString is the name of the function so it tells you that it is a [Function] if you try to console.log it.
nameString(value) calls the function with a value and returns a string that you could print to the console using console.log.


That is so easy! That makes perfect sense.

Thank you so much for your time,