Implicit Return

suggest change

Arrow functions may implicitly return values by simply omitting the curly braces that traditionally wrap a function’s body if their body only contains a single expression.

const foo = x => x + 1;
foo(1); // -> 2

When using implicit returns, object literals must be wrapped in parenthesis so that the curly braces are not mistaken for the opening of the function’s body.

const foo = () => { bar: 1 } // foo() returns undefined
const foo = () => ({ bar: 1 }) // foo() returns {bar: 1}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents