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.

If your codebase relies on non-standard behavior that involves reassigning constant variables (which is highly discouraged), you might choose to disable this rule. For example, if you target a legacy runtime with non-standard JavaScript semantics, standard practices may not apply to you.

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