Spot the Missing Return
Find the Mistake Easy
Question
This function should return the doubled value, but it returns undefined. What is wrong?
Code
function double(x) {
x * 2;
}
console.log(double(5));
Hint
The calculation is there, but the result is not sent back.
Explanation
The function body computes x * 2 but does not use return, so the result is discarded and the function returns undefined. The fix is return x * 2;. Without return, the function has no output.
Related Resources
Related Lessons
- Functions
Learn how functions work in programming.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.