Conditional expression in Arrow function
See original GitHub issueThe no-confusing-arrow rule is enabled, so the following syntax is an error:
const fn = a => a ? 1 : 2;
The arrow-body-style rule is enabled, so the following syntax is an error too:
const fn = a => { return a ? 1 : 2; };
So the only way to write it following the rules is the following one:
const fn = a => { if (a) return 2; return 3; };
Is this correct? Or is there another way to write the same stuff in a different way?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
How to use if-else condition in arrow function in JavaScript?
An arrow function can simply be seen as a concise version of a regular function, except that the return is implied (among a...
Read more >Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >How to Use ES6 Arrow Functions in JavaScript
Arrow functions can also be an excellent choice when you want to use conditional statements inside a function block. The following script defines...
Read more >Arrow functions, the basics
This creates a function func that accepts arguments arg1..argN , then evaluates the expression on the right side with their use and returns...
Read more >It's possible to use if statement in a arrow function with no " ...
The ternary if would work in the shorter syntax, but you have to return something in the else case since its required in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
allowParens
option is set to true, soshould not cause a linter error.
Got it
On Sun 19 Jul, 2020, 1:14 AM Jordan Harband, notifications@github.com wrote: