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.
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