> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-constant-binary-expression

[Added in v0.1.14](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.14)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ js.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-constant-binary-expression': 'error',
    },
  },
]);
```

## Rule Details

Disallows expressions where the operation is guaranteed to always produce the same result, indicating a likely logic error. This includes comparisons against newly constructed objects (which can never be referentially equal to anything), constant short-circuit expressions where the left-hand side determines the result regardless of the right-hand side, and comparisons that always evaluate to the same boolean value.

Examples of **incorrect** code for this rule:

```javascript
if (x === []) {}             // always false, new array is never === to anything

const value = x ?? "default" || y; // constant ?? on left when left is non-nullish

if (x === true && "foo") {}  // constant && with literal left side

if ({} === {}) {}            // two new objects are never equal
```

Examples of **correct** code for this rule:

```javascript
if (x === someVar) {
}

const value = x ?? y;

if (x && y) {
}

if (x === null) {
}
```

## Original Documentation

- [ESLint: no-constant-binary-expression](https://eslint.org/docs/latest/rules/no-constant-binary-expression)
- [Source code](https://github.com/eslint/eslint/blob/v9.39.1/lib/rules/no-constant-binary-expression.js)
