prefer-const
What it does
Section titled “What it does”Reports a let variable that is assigned once and could be a const: the single write is its initializer, a for-in or for-of head, or the first assignment statement in the same block as the declaration. A variable written in a nested block or function, a let of a for (;;) head, and a destructuring that assigns members or outer names are not reported.
Why it matters
Section titled “Why it matters”A let says the variable changes. When it never does, the keyword misleads the reader into looking for the later assignment, and const lets the compiler stop one.
To fix, write const.
Example
Section titled “Example”...let b = 2;let c = 3;c = 4;function f() {...function g() { let d; d = 1; return d;}Configuration
Section titled “Configuration”js: lint: rules: prefer-const: warn # off (default), warn, errorEnabled by the presets: js/typescript-eslint-recommended, js/biome-recommended.
Suppress one line with sudsy-disable-next-line prefer-const in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | prefer-const |
partial | the options keep their defaults (destructuring: any, ignoreReadBeforeAssign: false) |