A function has two ways to send a value out:
console.log()is the side window. The value goes out to the terminal, where you can read it. The rest of your program never gets it.returnis the front door. The value goes back to the line that called the function and takes the call’s place.
When a function only logs, nothing comes through the front door, so JavaScript puts undefined in the call’s place. It’s the same undefined a missing argument gets, JavaScript’s value for “nothing here.” This file prints 12 from inside the call, then undefined:
scratch/points.js
function showPoints(hits) {
console.log(hits * 3);
}
const score = showPoints(4);
console.log(score);
Seeing 12 on the screen doesn’t mean the function handed 12 back.