Skip to content

unicorn/prefer-logical-operator-over-ternary Style

🚧 An auto-fix is still under development.

What it does

This rule finds ternary expressions that can be simplified to a logical operator.

Why is this bad?

Using a logical operator is shorter and simpler than a ternary expression.

Example

Examples of incorrect code for this rule:

javascript
const foo = bar ? bar : baz;
console.log(foo ? foo : bar);

Examples of correct code for this rule: const foo = bar || baz; console.log(foo ?? bar);



## References
- [Rule Source](https://github.com/oxc-project/oxc/blob/36ebb3e7841818c238c44349d6cf859db4177d55/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs)

Released under the MIT License.