-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Closed
Description
https://github.com/airbnb/javascript#comparison--nested-ternaries
The recommended refactoring of
const foo = maybe1 > maybe2
? "bar"
: value1 > value2 ? "baz" : null;into
const maybeNull = value1 > value2 ? 'baz' : null;
const foo = maybe1 > maybe2 ? 'bar' : maybeNull;is not equivalent. In the latter, the value1 > value2 comparison is always evaluated, and one of 'baz' or null is also always evaluated. In this case, it is probably fine, but in general it has two problems:
- These extra evaluations may be expensive
- These extra evaluations may have side effects or throw when
maybe1 > maybe2.
Metadata
Metadata
Assignees
Labels
No labels