Missing Return Statement
Quick summary
Your function calculated a value but forgot to return it — the caller receives undefined instead of the expected result.
Why this happens
Computed a value but did not write
returnbefore itReturn statement is inside an if-block that does not always execute
Forgot to return from one branch of a conditional
Minimal example
function double(x) {
x * 2; // Computed but not returned!
}
console.log(double(5)); // undefinedfunction double(x) {
return x * 2; // Now it returns the result
}
console.log(double(5)); // 10Without return, the computed value is discarded and the function returns undefined. Adding return sends the value back to the caller.
How to diagnose
Check if the function returns undefined when it should return a value
Look for calculations that are not preceded by
returnVerify all code paths in conditionals have a return statement
How to fix
Add
returnbefore the expression that should be sent backEnsure all branches of if/else return a value
Add a default return at the end of the function
How to prevent
Always verify that functions meant to return a value have a return statement
Use TypeScript to catch missing returns at compile time