Null Safe Nullable Variable

Thursday, December 18, 2025

Please don't do this unless there's a solid reason.

So, I happened to see Javascript code similar to the following on a production app which I can't see the reason. Assuming redirectUrl is never null.

const url = isRedirect ? redirectUrl : "null";

The above renders the check further down useless:

if (url) {
  // Do something
}