Why is my function returning undefined when I have not mentioned that anywhere.
The crux of the issue is in the topic header.
All functions have to return something. If nothing is specified, they return undefined.
function doSomething() {
// do something
}
const something = doSomething();
console.log("something: ", something);
// undefined
You may however chose to ignore receiving something from the function.
function doSomething() {
// do something
}
doSomething();
Typically, I like to return at least a true or false - just for the heck of it. That’s overengineering to some, but that’s ok.
function doSomething() {
// do something
return true;
}