OK I have to admit this argument for using let
over const
for most cases in JavaScript/TypeScript almost has me convinced.
I'm sure I'm going to continue to prefer const
, but I see the point.
Video argument: https://www.epicweb.dev/talks/let-me-be
Screenshot from a social media thread where Dave Herman (a JS ES6 designer) states the following:
Your preferred style is indeed a popular one, possibly the most popular one. However IMO it leads to considerably worse code. 1/
People tend to think "letting readers know whether my local binding is mutated is important enough to signal with a keyword." I disagree 2/
Mutation is difficult to manage *in the large* and deserves careful annotation. Const doesn't help with this. 3/
In the small, it's much less useful. It's distracting to the reader of the code to be constantly informed "this binding is not mutated" 4/
Worse, it's confusing people because it's not telling you the value is immutable, just the binding. 5/
In fact, the traditional meaning of the keyword `const` is "this *value* is a constant." I.e., deeply immutable values only. 6/
So the benefit is low, the added noise level is high, and the code doesn't say what it means. 7/7
Reply
Expand (2 )
Collapse
(2)
More
Loading...