Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Stop Fearing the Undefined with Optional Chaining
April 27, 2026
We’ve all been there: trying to access a nested property like user.profile.address.city and watching the whole app crash because profile was null. Instead of writing long chains of if-statements, just use the optional chaining operator (?.). Writing user?.profile?.address?.city will safely return undefined instead of throwing an error if any part of the chain is missing. Pair it with the nullish coalescing operator (??) to provide a default value, and you’ve got a robust way to handle data that might not be there yet.