I add linters for js (es6) in my project, and for new configurations I found that they prevent using const
inside functions - only for module-level constants. And inside functions I should use let
. But I can't find any ground for such rule. Why?
For jscs it's for example
disallowConstOutsideModuleScope:
const
should only be used in module scope (not inside functions/blocks)
I understand that I can configure and switch off that rule, I just wonder what for it was enabled ? What is the motivation for such checking?
P.S. I have link https://madhatted.com/2016/1/25/let-it-be with block "Constantly const"
There is another school of thought on when to use let and const I’ll need to address. This strategy suggests developers use const as much as possible. Any variable that is not re-assigned should be declared with const.
I think this usage is poor practice. It adds an extra distraction to the process of programming, and results in code difficult to understand and change.
But I can't find that arguments valuable
const
unless you actually need a variable to change. – Warren