# operation-returning-nan

Rule `sonarjs/operation-returning-nan`. Arithmetic operations should not result in "NaN"

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2171 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/operation-returning-nan` | no | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3757/) |

## Code examples

### Incorrect: the rule reports this

```js
x = [1, 2];
var y = x / 4;  //Noncompliant
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/operation-returning-nan": "error",
    },
  },
];
```

## Related rules

- [sonarjs/non-number-in-arithmetic-expression](https://lintradar.dev/rules/sonarjs/non-number-in-arithmetic-expression.md): Arithmetic operators should only have numbers as operands
- [sonarjs/no-wildcard-import](https://lintradar.dev/rules/sonarjs/no-wildcard-import.md): Wildcard imports should not be used
- [sonarjs/prefer-immediate-return](https://lintradar.dev/rules/sonarjs/prefer-immediate-return.md): Local variables should not be declared and then immediately returned or thrown
- [sonarjs/no-variable-usage-before-declaration](https://lintradar.dev/rules/sonarjs/no-variable-usage-before-declaration.md): Variables declared with "var" should be declared before they are used
- [sonarjs/prefer-object-literal](https://lintradar.dev/rules/sonarjs/prefer-object-literal.md): Object literal syntax should be used
- [sonarjs/no-unused-function-argument](https://lintradar.dev/rules/sonarjs/no-unused-function-argument.md): Unused function parameters should be removed

---

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