Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Stop the "Undefined" Nightmares
April 29, 2026
If you're still writing long chains of "if (user && user.profile && user.profile.name)", it's time to fully embrace optional chaining (?.) and nullish coalescing (??). These operators make your code significantly more readable and resilient. For example, "const name = user?.profile?.name ?? 'Anonymous';" handles missing data gracefully without throwing an error.
Unlike the logical OR operator (||), the nullish coalescing operator only falls back if the value is null or undefined. This means if the user's name is an empty string, it won't be replaced by your default value. It keeps your logic flat and your intent clear, which your future self will definitely appreciate during a late-night debugging session.