# no-constant-binary-expression

Rule `eslint/no-constant-binary-expression`. Disallow expressions where the operation doesn't affect the value

- Source: eslint
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 234.4M weekly downloads of presets that enable it
- Trend: +44.0% last quarter
- Rank: #57 by reach, #925 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-constant-binary-expression` | yes | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-constant-binary-expression) |
| Oxlint | `no-constant-binary-expression` | yes | no | plugin `eslint`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-constant-binary-expression.html) |
| Biome | `suspicious/noConstantBinaryExpressions` | no | no | group suspicious, since 2.0.0 | [docs](https://biomejs.dev/linter/rules/no-constant-binary-expressions/) |

## Code examples

### Incorrect: the rule reports this

```js
const value1 = +x == null;

const value2 = condition ? x : {} || DEFAULT;

const value3 = !foo == null;

const value4 = new Boolean(foo) === true;

const objIsEmpty = someObj === {};

const arrIsEmpty = someArr === [];

const shortCircuit1 = condition1 && false && condition2;

const shortCircuit2 = condition1 || true || condition2;

const shortCircuit3 = condition1 ?? "non-nullish" ?? condition2;
```

### Correct: the rule accepts this

```js
const value1 = x == null;

const value2 = (condition ? x : {}) || DEFAULT;

const value3 = !(foo == null);

const value4 = Boolean(foo) === true;

const objIsEmpty = Object.keys(someObj).length === 0;

const arrIsEmpty = someArr.length === 0;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "no-constant-binary-expression": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-constant-binary-expression": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noConstantBinaryExpressions": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [ESLint recommended](https://lintradar.dev/presets/eslint-recommended.md) | ESLint | `@eslint/js` | 64 | 178.8M | +25.9% |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [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% |
| [Nuxt](https://lintradar.dev/presets/nuxt.md) | ESLint | `@nuxt/eslint-config` | 188 | 1.5M | +72.8% |
| [Google TypeScript Style](https://lintradar.dev/presets/gts.md) | ESLint | `gts` | 71 | 553.3K | +10.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [eslint/no-invalid-regexp](https://lintradar.dev/rules/eslint/no-invalid-regexp.md): Disallow invalid regular expression strings in `RegExp` constructors
- [eslint/no-empty-static-block](https://lintradar.dev/rules/eslint/no-empty-static-block.md): Disallow empty static blocks
- [eslint/no-delete-var](https://lintradar.dev/rules/eslint/no-delete-var.md): Disallow deleting variables
- [eslint/no-unassigned-vars](https://lintradar.dev/rules/eslint/no-unassigned-vars.md): Disallow `let` or `var` variables that are read but never assigned
- [eslint/no-new-native-nonconstructor](https://lintradar.dev/rules/eslint/no-new-native-nonconstructor.md): Disallow `new` operators with global non-constructor functions
- [eslint/no-fallthrough](https://lintradar.dev/rules/eslint/no-fallthrough.md): Disallow fallthrough of `case` statements

---

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