r/javascript • • Jul 22 '26

AskJS [AskJS] what's a javascript feature you mass-adopted way too late and felt dumb about

64 Upvotes

107 comments sorted by

View all comments

Show parent comment

1

u/azhder Jul 24 '26

It's easier if you allow yourself to not worry about accidentally overwriting a variable. With `var` and `let`, that's a possibility, but with `const` once you assign it, it's constantly pointing to a specific value.

I'd rather have

const value = valueFromArgs ?? 0;

than override

value = value ?? 0;

And as an added bonus, with most of the variables being `const`, you will easily notice the very few places that have `let` and possibly check it everything is all right - code smell. It's harder to notice a bad `let` if there are plenty of `let`s.