Spot the Missing Return
Question
This function returns undefined instead of the sum. What is wrong?
Code
const add = (a, b) => {
a + b;
};
console.log(add(2, 3));
Hint
Arrow functions with curly braces need an explicit return.
Explanation
When an arrow function uses curly braces { }, it has a block body and requires an explicit return statement. Without return, the function returns undefined. The fix is const add = (a, b) => { return a + b; }; or simply const add = (a, b) => a + b; (expression body without braces).
Related Resources
Related Lessons
- JavaScript Functions
Learn about arrow function return semantics.
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.