A previous article discussed the use of let, const, and var, suggesting that let is generally preferred, with const reserved for variables that should not be reassigned. This perspective generated considerable debate online, with many developers advocating for the use of const wherever possible, only resorting to let when reassignment is necessary. This approach is often enforced by tools like the prefer-const ESLint rule.
This article summarizes the arguments for and against preferring const, along with a personal conclusion on the subject.
Why Prefer const
- Reduced Decision Fatigue: A const-first approach eliminates the need to decide between let and const for each variable, streamlining the coding process. Linters can automate this rule.
- Preventing Reassignment Bugs: In complex functions, unintended reassignments can lead to bugs. Using const ensures a variable’s value remains consistent, especially within closures.
- Clarifying Mutation vs. Assignment: While beginners might confuse const with immutability, adopting const-first encourages understanding the distinction between variable assignment and object mutation early in the learning process.
- Enforcing Data Flow: For patterns like React Hooks, where values act as parameters with a unidirectional flow, const can prevent incorrect reassignments and reinforce proper data flow understanding.
- Potential Performance Gains: Some suggest that JavaScript engines might optimize code with const declarations more effectively, as they know these variables will not be reassigned.
Why Not Prefer const
- Obscuring Developer Intent: Overusing const can dilute its meaning, making it harder to identify variables where preventing reassignment is genuinely critical.
- Persistent Immutability Confusion: Despite explanations, the confusion between const (preventing reassignment) and immutability (preventing value modification) persists, especially among new developers. This can be counterproductive if the feature meant to help beginners ends up confusing them.
- Forcing Awkward Code Structures: A const-first rule might push developers to write complex ternary operations (e.g., const a = cond ? b : c) to avoid using let for conditionally assigned variables, even when an if statement would be clearer.
- Limited Bug Prevention Scope: Reassignment bugs are primarily an issue in specific scenarios: very large scopes, when reassigning parameters, or within nested functions. Many variables do not fall into these categories, and parameters cannot be declared with const anyway.
- Unproven Performance Advantages: JavaScript engines are generally sophisticated enough to identify variables assigned only once, regardless of whether var or let is used. Claims of performance benefits from const are often speculative and might even introduce overhead.
Conclusion
The choice between let and const is not a major concern for this author. The recommended approach is to adhere to existing conventions within a project’s codebase.
For those who find this distinction important, utilizing a linter to automatically check and fix variable declarations can prevent unnecessary delays during code reviews.
Ultimately, linters are tools meant to assist developers. If a specific linter rule proves to be more of a hindrance than a help to a team, it should be removed. Learning from practical experience is also crucial.

