const env_var = process.env.MY_ENV_VAR ?? throw new Error("MY_ENV_VAR is not set"); const env_var = process.env.MY_ENV_VAR ?? throw new Error("MY_ENV_VAR is not set");Null chaining is also a common pattern across most languages and is generally seen as readable
If you aren't going to be doing that, using const lets the reader know the assignment won't change to refer to a new value.
It's that simple.
There's a similar argument to be made for using forEach/ map / reduce / filter instead of a for loop. Each of those iterative methods has slightly different semantic intent. The only thing the for loop adds to the mix, and therefore the only reason to use them, is the availability of continue / break.
Hell, the same argument could be made for while loops vs for loops. What does a for loop really add that you couldn't get with a while loop?
As for your last point, I don't know of any linter that complains about the use of let when you reassign it. The ones I've used only complain if you use let when const would have worked identically in your code.
The fact that people write bad code is not down to let/const or linters. People always have and always will write crap and not understand why.
In 4 characters it clarifies something that could take 300 lines, 10 nested ifs, loops, etc; and, that trust disappears the moment someone, later down in the code *does* change the value.
Clarified intent, nearness-to-declaration, and linted protection are real benefits.
console.assert(maybeNull != null, 'variable not set')It's a function you could write for yourself and give it whatever semantics you feel is best. No changes to the language required for this one.