Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Say Goodbye to 'Undefined' Crashes
February 12, 2026
Dealing with deeply nested objects in JavaScript used to mean writing long, ugly chains of checks like if (user && user.profile && user.profile.email). You can ditch that verbosity by using optional chaining (?.). It short-circuits the evaluation if a reference is nullish, returning undefined instead of throwing an error.
Pair this with the nullish coalescing operator (??) to provide a sensible default value. For example, const email = user?.profile?.email ?? 'N/A'; is clean, readable, and keeps your app from crashing when data doesn't look exactly how you expected.