by ryanpetrich · 1y ago · 0 comments
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.
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.
console.assert(maybeNull != null, 'variable not set')