Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Safely Navigate Objects with Optional Chaining
March 10, 2026
Tired of writing long, defensive chains like `if (data && data.user && data.user.profile)`? Use optional chaining! The `?.` operator in JavaScript and TypeScript lets you safely access nested properties. If any part of the chain is null or undefined, it simply returns undefined instead of throwing a crash-inducing runtime error.
It keeps your logic clean and concise, especially when dealing with deeply nested API responses. It's one of those small syntax additions that drastically reduces the amount of boilerplate code you have to write and maintain.