Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Stop checking for null with Optional Chaining
March 21, 2026
If you are still writing deeply nested if-statements or long chains of logical ANDs to check if a property exists, it is time to embrace the optional chaining operator (?.). It allows you to read the value of a property located deep within a chain of connected objects without having to manually validate each reference.
Combine this with the nullish coalescing operator (??) to provide a fallback value, and your code becomes significantly more readable. It turns five lines of defensive checks into a single, elegant expression that is much easier for the next developer to maintain.