-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Where to place operators in a multi-line ternary? #1281
Copy link
Copy link
Closed
Labels
Description
My team uses airbnb's styleguide as our default for coding style, although we do deviate occasionally.
Does airbnb have an opinion on where the operators should go in a multi-line ternary?
It's not specifically talked about anywhere, but there is the example:
// better
const foo = maybe1 > maybe2
? 'bar'
: maybeNull;
one of our engs prefers this, with the justification that it's easier to read. If you read the first line by itself, then having the ? at the end lets you know that this is a ternary and is continuing. Otherwise, if you're skimming the code very fast, you might think that you're assigning foo a boolean value.
const foo = maybe1 > maybe2 ?
'bar' :
maybeNull;
And again, we're using multi-line ternaries because we have some long expressions and values to be assigned.
Reactions are currently unavailable