# values-not-convertible-to-numbers

Rule `sonarjs/values-not-convertible-to-numbers`. Values not convertible to numbers should not be used in numeric comparisons

- 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: #2180 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/values-not-convertible-to-numbers` | no | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3758/) |

## Code examples

### Incorrect: the rule reports this

```js
var x;  // x is currently "undefined"
if (someCondition()) {
  x = 42;
}

if (42 > x) {  // Noncompliant; "x" might still be "undefined"
  doSomething();
}

var obj = {prop: 42};
if (obj > 24) { // Noncompliant
  doSomething();
}
```

### Correct: the rule accepts this

```js
var x;
if (someCondition()) {
  x = 42;
} else {
  x = foo();
}

if (42 > x) {
  doSomething();
}

var obj = {prop: 42};
if (obj.prop > 24) {
  doSomething();
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/values-not-convertible-to-numbers": "error",
    },
  },
];
```

## Related rules

- [sonarjs/variable-name](https://lintradar.dev/rules/sonarjs/variable-name.md): Variable, property and parameter names should comply with a naming convention
- [sonarjs/unicode-aware-regex](https://lintradar.dev/rules/sonarjs/unicode-aware-regex.md): Regular expressions using Unicode character classes or property escapes should enable the unicode flag
- [sonarjs/too-many-break-or-continue-in-loop](https://lintradar.dev/rules/sonarjs/too-many-break-or-continue-in-loop.md): Loops should not contain more than a single "break" or "continue" statement
- [sonarjs/strings-comparison](https://lintradar.dev/rules/sonarjs/strings-comparison.md): Comparison operators should not be used with strings
- [sonarjs/shorthand-property-grouping](https://lintradar.dev/rules/sonarjs/shorthand-property-grouping.md): Shorthand object properties should be grouped at the beginning or end of an object declaration
- [sonarjs/prefer-object-literal](https://lintradar.dev/rules/sonarjs/prefer-object-literal.md): Object literal syntax should be used

---

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