functional/no-let

February 22, 2026 ยท View on GitHub

๐Ÿ“ Disallow mutable variables.

๐Ÿ’ผ This rule is enabled in the following configs: โ˜‘๏ธ lite, badge-noMutations noMutations, โœ… recommended, ๐Ÿ”’ strict.

This rule should be combined with ESLint's built-in no-var rule to enforce that all variables are declared as const.

Rule Details

In functional programming variables should not be mutable; use const instead.

โŒ Incorrect

/* eslint functional/no-let: "error" */

let x = 5;
/* eslint functional/no-let: "error" */

for (let i = 0; i < array.length; i++) {}

โœ… Correct

/* eslint functional/no-let: "error" */

const x = 5;
/* eslint functional/no-let: "error" */

for (const element of array) {
}
/* eslint functional/no-let: "error" */

for (const [index, element] of array.entries()) {
}

Options

This rule accepts an options object of the following type:

type Options = {
  allowInFunctions: boolean;
  ignoreIdentifierPattern?: string[] | string;
};

Default Options

const defaults = {
  allowInForLoopInit: false,
  allowInFunctions: false,
};

Preset Overrides

const recommendedAndLiteOptions = {
  allowInForLoopInit: true,
};

allowInForLoopInit

If set, lets inside of for a loop initializer are allowed. This does not include for...of or for...in loops as they should use const instead.

โŒ Incorrect

/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */

for (let element of array) {
}
/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */

for (let [index, element] of array.entries()) {
}

โœ… Correct

/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */

for (let i = 0; i < array.length; i++) {}

allowInFunctions

If true, the rule will not flag any statements that are inside of function bodies.

ignoreIdentifierPattern

This option takes a RegExp string or an array of RegExp strings. It allows for the ability to ignore violations based on a variable's name.