# no-unassigned-vars

Rule `eslint/no-unassigned-vars`. Disallow `let` or `var` variables that are read but never assigned

- Source: eslint
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 233.6M weekly downloads of presets that enable it
- Trend: +44.2% last quarter
- Rank: #59 by reach, #923 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-unassigned-vars` | yes | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-unassigned-vars) |
| Oxlint | `no-unassigned-vars` | yes | no | plugin `eslint`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unassigned-vars.html) |
| Biome | `suspicious/noUnassignedVariables` | no | no | group suspicious, since 2.1.0 | [docs](https://biomejs.dev/linter/rules/no-unassigned-variables/) |

## Code examples

### Incorrect: the rule reports this

```js
let status;
if (status === 'ready') {
  console.log('Ready!');
}

let user;
greet(user);

function test() {
  let error;
  return error || "Unknown error";
}

let options;
const { debug } = options || {};

let flag;
while (!flag) {
  // Do something...
}

let config;
function init() {
  return config?.enabled;
}
```

```ts
let value: number | undefined;
console.log(value);
```

### Correct: the rule accepts this

```ts
declare let value: number | undefined;
console.log(value);

declare module "my-module" {
  let value: string;
  export = value;
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "no-unassigned-vars": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-unassigned-vars": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noUnassignedVariables": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [ESLint recommended](https://lintradar.dev/presets/eslint-recommended.md) | ESLint | `@eslint/js` | 64 | 178.8M | +25.9% |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Nuxt](https://lintradar.dev/presets/nuxt.md) | ESLint | `@nuxt/eslint-config` | 188 | 1.5M | +72.8% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [eslint/no-empty-static-block](https://lintradar.dev/rules/eslint/no-empty-static-block.md): Disallow empty static blocks
- [eslint/no-constant-binary-expression](https://lintradar.dev/rules/eslint/no-constant-binary-expression.md): Disallow expressions where the operation doesn't affect the value
- [eslint/no-invalid-regexp](https://lintradar.dev/rules/eslint/no-invalid-regexp.md): Disallow invalid regular expression strings in `RegExp` constructors
- [eslint/no-new-native-nonconstructor](https://lintradar.dev/rules/eslint/no-new-native-nonconstructor.md): Disallow `new` operators with global non-constructor functions
- [eslint/no-delete-var](https://lintradar.dev/rules/eslint/no-delete-var.md): Disallow deleting variables
- [eslint/no-fallthrough](https://lintradar.dev/rules/eslint/no-fallthrough.md): Disallow fallthrough of `case` statements

---

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