Implicit Return
suggest changeArrow 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}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents