Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Cleaning Up Your Logic with Optional Chaining
February 14, 2026
We've all been there: writing long, defensive chains like 'if (user && user.profile && user.profile.settings)' just to avoid a 'cannot read property of undefined' error. In modern JavaScript and TypeScript, you can replace that entire headache with the optional chaining operator ?.. Just write user?.profile?.settings instead. If any part of the chain is null or undefined, the whole expression safely returns undefined instead of crashing your app. It keeps your code much leaner and far easier to scan at a glance.