Skip to content

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 return before it

  • Return statement is inside an if-block that does not always execute

  • Forgot to return from one branch of a conditional

Minimal example

✗ Broken code
function double(x) {
  x * 2; // Computed but not returned!
}
console.log(double(5)); // undefined
✓ Fixed code
function double(x) {
  return x * 2; // Now it returns the result
}
console.log(double(5)); // 10

Without 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 return

  • Verify all code paths in conditionals have a return statement

How to fix

  • Add return before the expression that should be sent back

  • Ensure 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

Related Resources

Related Glossary

Related Lessons

← Back to language