In today's edition of Adventures in Legacy Code, I came across the following:
if( tokenInfo && tokenInfo !== undefined && tokenInfo !== null && tokenInfo !== "" )
I get it—we need to prevent things from going wrong, but the sight of it brings helicopter parenting to mind. Also, it's not really null-checking, but also undefined- and empty-string-checking. This is another benefit you can gain from TypeScript—the peace of mind that it won't compile if you're sending the wrong information.
I'm taking Patricia Aas's advice, and I'm choosing to frame this in the mental model of the developers who created it at time it was created rather than being overly critical. It's just an opinion, after all!
What are your thoughts? How are you checking for empty or null values? Bonus if you comment with examples in other programming languages!