DEV Community

Toolloom
Toolloom

Posted on • Originally published at toolloom.com on

Ditch the Null Checks with Optional Chaining

Are you still writing verbose checks like if (user && user.profile && user.profile.address) just to safely access deeply nested data? Stop the madness! Modern JavaScript introduced the Optional Chaining operator (?.). Now you can safely access properties like this: user?.profile?.address?.street. If *any* part of that chain is null or undefined, the expression gracefully short-circuits and returns undefined, saving you tons of boilerplate code and potential runtime errors. It drastically cleans up API response handling.

Top comments (0)