Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Stop Fearing Null Pointers with Optional Chaining
March 31, 2026
If you're tired of writing long logical chains just to check if a nested property exists, optional chaining (?.) is your best friend. It short-circuits the evaluation, returning undefined instead of throwing an error if a reference is null or undefined.
Combine it with the nullish coalescing operator (??) to provide a sensible default value. This pattern makes your code significantly more readable and much less brittle when you're dealing with unpredictable API responses or complex state objects.