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 an implicit return, wrap an object literal in parentheses. Otherwise the braces are a block, and bar: is a label, so the function returns undefined. These are two separate examples:

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

Feedback about page:

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



Table Of Contents