# bitwise-operators

Rule `sonarjs/bitwise-operators`. Bitwise operators should not be used in boolean contexts

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1187 by reach, #488 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/bitwise-operators` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1529/) |

## Code examples

### Incorrect: the rule reports this

```js
if (a & b) { ... } // Noncompliant; & used in error
```

### Correct: the rule accepts this

```js
if (a && b) { ... }
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/bitwise-operators": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/aws-sqs-unencrypted-queue](https://lintradar.dev/rules/sonarjs/aws-sqs-unencrypted-queue.md): SQS queues should be encrypted
- [sonarjs/block-scoped-var](https://lintradar.dev/rules/sonarjs/block-scoped-var.md): Variables should be used in the blocks where they are declared
- [sonarjs/aws-sns-unencrypted-topics](https://lintradar.dev/rules/sonarjs/aws-sns-unencrypted-topics.md): Amazon SNS topics should be encrypted at rest
- [sonarjs/call-argument-line](https://lintradar.dev/rules/sonarjs/call-argument-line.md): Function call arguments should not start on new lines
- [sonarjs/aws-sagemaker-unencrypted-notebook](https://lintradar.dev/rules/sonarjs/aws-sagemaker-unencrypted-notebook.md): SageMaker notebook instances should be encrypted at rest
- [sonarjs/chai-determinate-assertion](https://lintradar.dev/rules/sonarjs/chai-determinate-assertion.md): Chai assertions should have only one reason to succeed

---

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