felixge / felixge/node-style-guide

Ternary operators, again

Open
#89 2 comments 1 reaction 0 assignees View on GitHub
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.