# no-unneeded-ternary

Rule `eslint/no-unneeded-ternary`. Disallow ternary operators when simpler alternatives exist

- Source: eslint
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 45.3M weekly downloads of presets that enable it
- Trend: +59.7% last quarter
- Rank: #307 by reach, #717 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-unneeded-ternary` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-unneeded-ternary) |
| Oxlint | `no-unneeded-ternary` | no | unsafe | plugin `eslint`, category suspicious | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.html) |
| Biome | `complexity/noUselessTernary` | yes | unsafe | group complexity, since 1.5.0 | [docs](https://biomejs.dev/linter/rules/no-useless-ternary/) |

## Code examples

### Incorrect: the rule reports this

```js
const a = x === 2 ? true : false;

const b = x ? true : false;
```

### Correct: the rule accepts this

```js
const a = x === 2 ? "Yes" : "No";

const b = x !== false;

const c = x ? "Yes" : "No";

const d = x ? y : x;

f(x ? x : 1); // default assignment - would be disallowed if defaultAssignment option set to false. See option details below.
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "no-unneeded-ternary": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-unneeded-ternary": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "complexity": {
        "noUselessTernary": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [JavaScript Standard Style](https://lintradar.dev/presets/standard.md) | ESLint | `eslint-config-standard` | 161 | 3.1M | +12.9% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Anthony Fu's config](https://lintradar.dev/presets/antfu.md) | ESLint | `@antfu/eslint-config` | 294 | 758.7K | +49.9% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [neostandard](https://lintradar.dev/presets/neostandard.md) | ESLint | `neostandard` | 95 | 317.6K | +50.2% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [eslint/prefer-regex-literals](https://lintradar.dev/rules/eslint/prefer-regex-literals.md): Disallow use of the `RegExp` constructor in favor of regular expression literals
- [eslint/no-extra-label](https://lintradar.dev/rules/eslint/no-extra-label.md): Disallow unnecessary labels
- [eslint/default-case-last](https://lintradar.dev/rules/eslint/default-case-last.md): Enforce `default` clauses in `switch` statements to be last
- [eslint/no-array-constructor](https://lintradar.dev/rules/eslint/no-array-constructor.md): Disallow `Array` constructors
- [eslint/no-use-before-define](https://lintradar.dev/rules/eslint/no-use-before-define.md): Disallow the use of variables before they are defined
- [eslint/dot-notation](https://lintradar.dev/rules/eslint/dot-notation.md): Enforce dot notation whenever possible

---

Web page: https://lintradar.dev/rules/eslint/no-unneeded-ternary. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
