DEV Community

Toolloom
Toolloom

Posted on • Originally published at toolloom.com on

Stop Fearing the Undefined

If you are tired of writing long chains of 'if' statements to avoid errors when accessing nested properties in JavaScript or TypeScript, start leaning on optional chaining (?.). It short-circuits the evaluation if a reference is nullish, returning undefined instead of throwing an error. Pair it with the nullish coalescing operator (??) to provide a default value, and your data-fetching logic will look significantly cleaner.

Top comments (0)