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/25ddb3519289dfe2a51e53b9b0c355d8ad950bbc/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs)

Released under the MIT License.