DEV Community

Mohamed Idris
Mohamed Idris

Posted on

Implicit vs Explicit return?!

Implicit return means a function returns a value without using the return keyword explicitly.

This happens in arrow functions when the function body is a single expression and does not use {}.

Example

Implicit return:

const add = (a, b) => a + b;
Enter fullscreen mode Exit fullscreen mode

This automatically returns a + b.

Explicit return:

const add = (a, b) => {
  return a + b;
};
Enter fullscreen mode Exit fullscreen mode

Key rule

  • ✅ No {}implicit return
  • {} used → must use return

In JSX (very common in React)

const Item = () => <div>Hello</div>;
Enter fullscreen mode Exit fullscreen mode

Equivalent to:

const Item = () => {
  return <div>Hello</div>;
};
Enter fullscreen mode Exit fullscreen mode

In short:
Implicit return = JavaScript returns the expression for you.

Top comments (0)