Daily Software Tips & Tricks

Bite-sized knowledge to improve your coding skills daily.

Cleaner Logic with Nullish Coalescing

March 6, 2026

Stop writing deeply nested `if` statements or long `&&` chains just to check if a property exists. Use optional chaining (`?.`) to safely access nested properties without throwing an error if a parent is null. Pair this with the nullish coalescing operator (`??`) to provide a fallback value only when the result is `null` or `undefined`. Unlike the logical OR (`||`), it won't trigger on "falsy" values like `0` or an empty string, which prevents a lot of common UI bugs.