# prefer-const

Rule `eslint/prefer-const`. Require `const` declarations for variables that are never reassigned after declared

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 223.9M weekly downloads of presets that enable it
- Trend: +34.8% last quarter
- Rank: #69 by reach, #1066 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `prefer-const` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/prefer-const) |
| Oxlint | `prefer-const` | no | safe | plugin `eslint`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/prefer-const.html) |
| Biome | `style/useConst` | yes | safe | group style, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/use-const/) |

## Code examples

### Incorrect: the rule reports this

```js
// it's initialized and never reassigned.
let a = 3;
console.log(a);

let b;
b = 0;
console.log(b);

class C {
    static {
        let a;
        a = 0;
        console.log(a);
    }
}

// `i` is redefined (not reassigned) on each loop step.
for (let i in [1, 2, 3]) {
    console.log(i);
}

// `a` is redefined (not reassigned) on each loop step.
for (let a of [1, 2, 3]) {
    console.log(a);
}
```

### Correct: the rule accepts this

```js
// using const.
const a = 0;

// it's never initialized.
let b;
console.log(b);

// it's reassigned after initialized.
let c;
c = 0;
c = 1;
console.log(c);

// it's initialized in a different block from the declaration.
let d;
if (true) {
    d = 0;
}
console.log(d);

// it's initialized in a different scope.
let e;
class C {
    #x;
    static {
        e = obj => obj.#x;
    }
}

// it's initialized at a place that we cannot write a variable declaration.
let f;
if (true) f = 0;
// …
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "prefer-const": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "prefer-const": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useConst": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [typescript-eslint recommended](https://lintradar.dev/presets/typescript-eslint-recommended.md) | ESLint | `@typescript-eslint/eslint-plugin` | 24 | 175.9M | +29.5% |
| [typescript-eslint strict](https://lintradar.dev/presets/typescript-eslint-strict.md) | ESLint | `@typescript-eslint/eslint-plugin` | 32 | 175.9M | +29.5% |
| [typescript-eslint stylistic](https://lintradar.dev/presets/typescript-eslint-stylistic.md) | ESLint | `@typescript-eslint/eslint-plugin` | 17 | 175.9M | +29.5% |
| [typescript-eslint strict type-checked](https://lintradar.dev/presets/typescript-eslint-strict-type-checked.md) | ESLint | `@typescript-eslint/eslint-plugin` | 75 | 175.9M | +29.5% |
| [typescript-eslint recommended type-checked](https://lintradar.dev/presets/typescript-eslint-recommended-type-checked.md) | ESLint | `@typescript-eslint/eslint-plugin` | 47 | 175.9M | +29.5% |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [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% |
| [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% |
| [Anthony Fu's config](https://lintradar.dev/presets/antfu.md) | ESLint | `@antfu/eslint-config` | 294 | 758.7K | +49.9% |
| [Google](https://lintradar.dev/presets/google.md) | ESLint | `eslint-config-google` | 60 | 646.4K | +18.9% |
| [Google TypeScript Style](https://lintradar.dev/presets/gts.md) | ESLint | `gts` | 71 | 553.3K | +10.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [neostandard](https://lintradar.dev/presets/neostandard.md) | ESLint | `neostandard` | 95 | 317.6K | +50.2% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [eslint/no-prototype-builtins](https://lintradar.dev/rules/eslint/no-prototype-builtins.md): Disallow calling some `Object.prototype` methods directly on objects
- [eslint/no-redeclare](https://lintradar.dev/rules/eslint/no-redeclare.md): Disallow variable redeclaration
- [eslint/no-case-declarations](https://lintradar.dev/rules/eslint/no-case-declarations.md): Disallow lexical declarations in case clauses
- [eslint/prefer-rest-params](https://lintradar.dev/rules/eslint/prefer-rest-params.md): Require rest parameters instead of `arguments`
- [eslint/no-dupe-args](https://lintradar.dev/rules/eslint/no-dupe-args.md): Disallow duplicate arguments in `function` definitions
- [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/prefer-const. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
