Use-Ternary-Operator¶
Sourcery rule id: use-ternary-operator
¶
Description¶
Replace if statement with ternary operator
Before¶
if (cond) {
var x = 1
} else {
var x = 2
}
After¶
var x = cond ? 1 : 2;
Explanation¶
The ternary operator is a simpler and more elegant way to write conditional assignments to a variable than the long form.