Skip to content

constantAssignments

Reports attempting to reassign variables declared with const.

✅ This rule is included in the ts untyped preset.

The const keyword creates a read-only reference to a value, preventing reassignment. While properties of const objects and elements of const arrays can be mutated, the binding itself cannot be reassigned. Attempting to reassign a const variable results in a runtime error.

const value = 1;
value = 2;
const result = getValue();
result = getOtherValue();
const counter = 0;
counter++;
const { property } = object;
property = "new value";
for (const item of items) {
item = processItem(item);
}

This rule is not configurable.

This rule should always be enabled. Reassigning a const variable is a runtime error in JavaScript and TypeScript, so this rule helps catch such issues during development.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.