# different-types-comparison

Rule `sonarjs/different-types-comparison`. Strict equality operators should not be used with dissimilar types

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1202 by reach, #503 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/different-types-comparison` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3403/) |

## Code examples

### Incorrect: the rule reports this

```js
var a = 8;
var b = "8";

if (a === b) {  // Noncompliant; always false
  // ...
}
```

### Correct: the rule accepts this

```js
var a = 8;
var b = "8";

if (a == b) {
  // ...
}
```

```js
var a = 8;
var b = "8";

if (a === Number(b)) {
  // ...
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/different-types-comparison": "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/deprecation](https://lintradar.dev/rules/sonarjs/deprecation.md): Deprecated APIs should not be used
- [sonarjs/disabled-auto-escaping](https://lintradar.dev/rules/sonarjs/disabled-auto-escaping.md): Auto-escaping in HTML template engines should not be disabled
- [sonarjs/csrf](https://lintradar.dev/rules/sonarjs/csrf.md): CSRF protections should not be disabled
- [sonarjs/disabled-resource-integrity](https://lintradar.dev/rules/sonarjs/disabled-resource-integrity.md): Remote artifacts should not be used without integrity checks
- [sonarjs/cors](https://lintradar.dev/rules/sonarjs/cors.md): Cross-Origin Resource Sharing (CORS) policy should be restricted to trusted origins
- [sonarjs/disabled-timeout](https://lintradar.dev/rules/sonarjs/disabled-timeout.md): Disabling Mocha timeouts should be explicit

---

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