Let me remove some noise for you that hopefully clears some things up.
const timeFuncRuntime = funcParameter => {
console.log(funcParameter);
return "foo";
}
timeFuncRuntime("bar");
console.log(timeFuncRuntime());
So what happens in the above? Why does the console print out bar, undefined then foo?
Let's have a look at this section by section.
const timeFuncRuntime = funcParameter => {
console.log(funcParameter);
return "foo";
}
This first piece of code defines a function and saves it in the constant timeFuncRunTime. This function accepts one parameter funcParameter. When called it will log this parameter and return "foo";
timeFuncRuntime("bar");
This calls the timeFuncRuntime function with funcParameter set to "bar". This will log the first result bar. The return value is ignored (not saved in a variable nor passed on to another function).
console.log(timeFuncRuntime());
// call without parameters ^
This line is the trouble maker. You want to log the timeFuncRuntime() return value (which is "foo"). However the function has to be called first to get this value. This time you call it with no arguments. This means that funcParameter will be undefined. You then log this parameter, resulting in the undefined in the console output. This is followed by a log of the return value foo.
If the intent was to log the return value after the function was called you will have to save the return value inside a variable, or pass it directly to console.log.
const timeFuncRuntime = funcParameter => {
console.log(funcParameter);
return "foo";
}
console.log("save the return value inside a variable");
const returnValue = timeFuncRuntime("bar");
console.log(returnValue); // <- log the variable
console.log("pass the return value to `console.log` directly");
console.log(timeFuncRuntime("bar"));