felixge / felixge/node-style-guide
Ternary operators, again
- Dominant language
- JavaScript
- Stars
- 5k
- Forks
- 893
- PR merge metrics
- No merged PRs in 30d
Description
I agree that multi-line ternary operators make sense. However, the following is (as far as I know) bad, due to ASI:
```
var foo = (a === b)
? 1
: 2;
```
JShint will throw an error on this code, saying “Bad line breaking before '?'”.
If you insist on using multi-line ternary operators, you might prefer the following style:
```
var foo = (a === b) ?
1 :
2;
```
I agree that it is less readable, because the question mark and the colon are more obvious at the beginning of the line. But I wouldn’t want to mess with ASI and depend on implicit fixes of the JS engine, either.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.