# no-undef

Rule `eslint/no-undef`. Disallow the use of undeclared variables unless mentioned in `/*global */` comments

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const foo = someFunction();
const bar = a + 1;
```

### Correct: the rule accepts this

```js
/*global someFunction, a*/
/*eslint no-undef: "error"*/

const foo = someFunction();
const bar = a + 1;
```

Examples from the ESLint documentation.

## Enable it

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-undef": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "correctness": {
        "noUndeclaredVariables": "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% |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [JavaScript Standard Style](https://lintradar.dev/presets/standard.md) | ESLint | `eslint-config-standard` | 161 | 3.1M | +12.9% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |

## Related rules

- [eslint/no-var](https://lintradar.dev/rules/eslint/no-var.md): Require `let` or `const` instead of `var`
- [eslint/prefer-spread](https://lintradar.dev/rules/eslint/prefer-spread.md): Require spread operators instead of `.apply()`
- [eslint/no-empty](https://lintradar.dev/rules/eslint/no-empty.md): Disallow empty block statements
- [eslint/no-unexpected-multiline](https://lintradar.dev/rules/eslint/no-unexpected-multiline.md): Disallow confusing multiline expressions
- [eslint/preserve-caught-error](https://lintradar.dev/rules/eslint/preserve-caught-error.md): Disallow losing originally caught error when re-throwing custom errors
- [eslint/no-useless-assignment](https://lintradar.dev/rules/eslint/no-useless-assignment.md): Disallow variable assignments when the value is not used

---

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