How JavaScript Functions Return Values
The return statement pops the call stack frame. Here is how return values work, including undefined and arrow shorthand.
How JavaScript Functions Return Values
The return statement is how a function sends a value back to its caller and finishes. Understanding it precisely matters for closures, async, and interviews.
What return Does
- Evaluates the expression after
return. - Hands that value to the caller.
- Immediately pops the current frame from the call stack.
Any code after return in the function body is not executed.
Default Return Value
If a function has no return, or return with no expression, it returns undefined:
function greet() { console.log("hi"); } const r = greet(); // logs "hi", r is undefined function noop() { return; } const r2 = noop(); // undefined
Returning Values
function add(a, b) { return a + b; } const sum = add(2, 3); // 5
Arrow Function Shorthand
An arrow function with an expression body returns that expression implicitly:
const add = (a, b) => a + b; // returns a + b const greet = () => { return "hi"; }; // explicit return const noop = () => {}; // returns undefined
If you use a block body in an arrow, you must write return explicitly.
Returning Objects From Arrows
A common pitfall: wrapping an object literal in parentheses is required for shorthand:
const makeUser = () => ({ name: "Kunal" }); // returns the object const makeUserBad = () => { name: "Kunal" }; // returns undefined (block body, no return)
Early Returns
return can be used to short-circuit:
function divide(a, b) { if (b === 0) return null; // early return return a / b; }
Early returns make code easier to read than nested if/else.
Returning Functions (Higher-Order)
A function can return another function. The returned function keeps a reference to the outer variable environment (closure):
function multiplier(factor) { return (n) => n * factor; } const double = multiplier(2); double(5); // 10
The Takeaway
return evaluates an expression, hands it to the caller, and pops the call stack frame. No return means undefined. Arrow shorthand returns implicitly, but block bodies need explicit return. Returning a function creates a closure that keeps the outer scope alive.
undefined. If a function has no return, or a return with no expression, it returns undefined to the caller.
It evaluates the return expression, hands the value to the caller, and immediately pops the current frame from the call stack. Code after return in the function body is not executed.
Because the braces are interpreted as a block body, not an object literal. Wrapping the object in parentheses (n) => ({ x: 1 }) makes it an expression body that returns the object.
Yes. A function that returns another function is a higher-order function. The returned function keeps a reference to the outer variable environment, creating a closure.
No. An arrow with a block body (=> { ... }) needs an explicit return statement. Only an arrow with an expression body (=> expr) returns the expression implicitly.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

