Skip to content

Conversation

@textbook
Copy link
Member

@textbook textbook commented Oct 21, 2019

Arrow functions that just return a value have two options:

  1. () => value; or
  2. () => { return value; }.

If they do anything other than just return, the braces are not optional. Therefore, in line with principle 2, perhaps we should always encourage the second option.

Arrow functions that just return a value have two options:

 1. `() => value`; or
 2. `() => { return value; }`.

If they do anything other than just return, the braces are not optional.
Therefore, in line with principle 2, perhaps we should always encourage
the first option.
@textbook textbook added the enhancement New feature or request label Oct 21, 2019
@textbook
Copy link
Member Author

arrow-parens felt like an easier sell as they're required in all but one case:

const noParams = () => "foo";
let oneSimpleParam = param =>  "foo";
oneSimpleParam = (param) => "foo";
const oneDestructuredParam = ({ foo, bar }) => "foo";
const oneRestParam = (...params) => "foo";
const multipleParams = (first, second) => "foo";

but arrow-body-style usage is more mixed. However, the common confusion around returning objects from arrow functions makes me lean towards inclusion:

const returnsObject = () => ({ foo: 123 });
const returnsUndefined = () => { foo: 123 };
const syntaxError = () => { foo: 123, bax: 456 };

@textbook textbook changed the base branch from master to main July 6, 2023 09:04
@textbook textbook force-pushed the main branch 2 times, most recently from f233f60 to 6bc8f67 Compare July 6, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant