# eslint-plugin-prefer-let

> Rule to prefer using `let` to bind names to values

Latest version **4.2.2** (published 2026-03-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-prefer-let
pnpm add eslint-plugin-prefer-let
yarn add eslint-plugin-prefer-let
bun add eslint-plugin-prefer-let
```

## Health

**Score 50/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 4.2.2 |
| Published | 2026-03-28 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 10 |
| Maintainers | cowboyd, cherewaty, frontsidejack |
| Keywords | eslint, eslintplugin, eslint-plugin |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-prefer-let
- Repository: https://github.com/thefrontside/javascript
- Homepage: https://github.com/thefrontside/javascript#readme
- Issues: https://github.com/thefrontside/javascript/issues
- npm.io page: https://npm.io/package/eslint-plugin-prefer-let

## Dependencies (1)

- [requireindex](https://npm.io/package/requireindex.md) ~1.2.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 4.2.2 (latest) — 2026-03-28
- 3.0.1-ad1d4bc (changeset-release_v3) — 2021-11-03
- 3.0.0-9bf1e83 (sync-versions) — 2021-10-26
- 3.0.0-e64bfd3 (changeset-release_v2) — 2021-10-26
- 2.0.0-1c687b4 (bump-versions) — 2021-10-26
- 1.1.0-2fd3c42 (update-eslint) — 2021-10-21
- 1.1.0-d5b9153 (upgrade-to-typescript-4-1) — 2021-01-06
- 1.0.2-edcc9a5 (dependabot_npm__and__yarn_eslint-4.18.2) — 2020-08-17
- 1.0.2-5eb4678 (typescript-upgrade) — 2020-08-17
- 1.0.2-447f893 (mk_remove-deps) — 2020-07-08
- 4.2.1 — 2026-03-25
- 4.2.0 — 2026-03-13
- 4.1.0 — 2026-02-17
- 4.0.1 — 2026-01-07
- 4.0.0 — 2024-07-15
- … 11 more at https://npm.io/package/eslint-plugin-prefer-let/versions

## README

# eslint-plugin-prefer-let

An eslint plugin to encourage semantic of usage of `let` and `const`.

Things being basically equal, code should speak to humans first, and
computers second. As such, JavaScript codebases should follow the
long-standing conventions set forth by both formal symbolic logic and
the practice of functional programming.

Usage of the `const` keyword to bind an _intermediate_ value of a
computation places emphasis on the compiler and its role in
ensuring that a _reference_ never changes. By contrast using `let` in
the same situation reads, in plain English, the programmer's intent to
declare a name value binding.

It is this plugin's opinion that preventing reassignment of `let`
bindings is better accomplished as a linting rule.

`const` bindings _are_ allowed at the top-level of a module's scope so
that it can represent a value that is a true, dependency-free constant
such as `π`, `ℯ`, etc...


Good:

``` javascript
const PI = 3.14;

function area(radius) {
  let r2 = radius * radius;
  return PI * r2;
}

```

Bad:

``` javascript
function volume(radius) {
  const a = area(radius);
  return a * radius / 2
}

```

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
$ npm i eslint --save-dev
```

Next, install `eslint-plugin-prefer-let`:

```
$ npm install eslint-plugin-prefer-let --save-dev
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-prefer-let` globally.

## Usage

Add `prefer-let` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
    "plugins": [
        "prefer-let"
    ]
}
```


Then configure the rules you want to use under the rules section.

```json
{
    "rules": {
        "prefer-let/prefer-let": 2
    }
}
```

### Options

#### `forceUpperCaseConst`

When set to `true`, this option enforces `const` for top-level `UPPER_CASE` names (e.g. `PI`, `API_BASE_URL`)

```json
{
    "rules": {
        "prefer-let/prefer-let": [2, { "forceUpperCaseConst": true }]
    }
}
```

This makes the distinction between true constants and regular bindings explicit and machine-enforced.

Good:

```javascript
const PI = 3.14;
const API_BASE_URL = 'https://example.com';

let config = loadConfig();
```

Bad:

```javascript
const config = loadConfig();  // not UPPER_CASE — use let
let PI = 3.14;                // UPPER_CASE — use const
```

### Possible Conflicts

This plugin may conflict with other plugins or configs that set `eslint prefer-const`. You can configure the rules to avoid this:

```json
{
    "rules": {
        "prefer-let/prefer-let": 2,
        "prefer-const": "off"
    }
}
```

---
_Source: https://npm.io/package/eslint-plugin-prefer-let · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
