Facebook Pixel
How JavaScript Functions Return Values

Why does an arrow function with an object literal need parentheses?

The answer

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.

More FAQs in How JavaScript Functions Return Values

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.

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.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.