Possible error in Certified Full Stack Curriculum Javascript Functions Quiz

This is the link to the quiz:

Question 8:

What value will be returned in the following code example?

function greet () {
  console.log("Hello there!");
}

greet();

The choices are:
undefined
null
TypeError
NaN

The answer accepted by the quiz is undefined.

I believe this is misleading. undefined only appears if the function is called and the result is returned:

If the question was

What value will be returned in the following code example?

function greet () {
  console.log("Hello there!");
}

console.log(greet());

then the correct answer would be

Hello there!
undefined

Am I correct in my understanding?

The word return has special, specific meaning. What does the word return mean?

btw, the question will be replaced soon. But also what Jeremy is saying

EDIT: I was thinking of a different question in that quiz, sorry, this one does not have plans for replacement (yet)

1 Like

Hi Jeremy

I edited my question just as you responded, so you may have responded to it before the edited version went up.

Please could you read my question again and give me feedback.

Many thanks

My reply is still something you should read and answer.

what is printed by the console.log is not the value returned, console.log prints to the console only

1 Like

Thanks Jeremy

I think return means the function will return something when called and if the return keyword is missing, or if it is there with no value after it, then undefined will be returned.

However, my thought was that, if the code in the question is run, Hello there! would be displayed on the console but undefined wouldn’t. I thought undefined would only be displayed if the function was ‘passed’ to a variable or console logged.

This is all true

Sure, but that does not change what is returned by the function.

I’m not sure what this means?

Thanks Jeremy for replying, and so quickly :slight_smile:

I thought undefined would only be displayed in the console in the following:

function greet () {
  console.log("Hello there!");
}

console.log(greet());

or

function greet () {
  console.log("Hello there!");
}
let a = greet();
console.log(a);

I use this last point because of what is in the transcript for the What Is the Purpose of Functions, and How Do They Work? lecture:

When a function finishes its execution, it will always return a value. By default, the return value will be undefined. Here is an example:

function doSomething() {
    console.log("Doing something...");
}

let result = doSomething();
console.log(result); // undefined

Ok, but I don’t think weather you log the return value or not changes what the return value is?

True - I understand now - thanks for your help

1 Like