Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Cleaning Up Conditional Logic in JavaScript
March 3, 2026
If you're still writing long chains of checks like if (user && user.profile && user.profile.name), it's time to embrace optional chaining. Using user?.profile?.name is not only cleaner but much more resilient to the dreaded cannot read property of undefined errors. It makes your intent clear: you're looking for a value that might not be there.
To take it a step further, look into logical nullish assignment (??=). It allows you to assign a value to a variable only if that variable is currently null or undefined. These little syntax sugars keep your functions lean and help you focus on the actual business logic rather than defensive null-checking.