# Prefer using a logical operator over a ternary 💼 This rule is enabled in the following [configs](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config): ✅ `recommended`, ☑️ `unopinionated`. 💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). Disallow ternary operators when simpler logical operator alternatives exist. Ideally, most reported cases have an equivalent [`Logical OR(||)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR) expression. The rule intentionally provides suggestions instead of auto-fixes, because in many cases, the [nullish coalescing operator (`??`)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) should be preferred. ## Examples ```js // ❌ foo ? foo : bar; // ✅ foo ?? bar; // ✅ foo || bar; ``` ```js // ❌ foo.bar ? foo.bar : foo.baz // ✅ foo.bar ?? foo.baz ``` ```js // ❌ foo?.bar ? foo.bar : baz // ✅ foo?.bar ?? baz ``` ```js // ❌ !bar ? foo : bar; // ✅ bar ?? foo; ``` ```js // ✅ foo ? bar : baz; ```