loading...
Cover image for A beginner friendly guide to optional chaining in Javascript

A beginner friendly guide to optional chaining in Javascript

deevoid profile image Dev ・1 min read

Optional Chaining has become one of my favorite ES2020 features.

Optional chaining allows you to safely access the nested object properties without the hassle to check validity of each one of them.
Instead of using && to check for null or undefined, directly use ?.
When you want to use an object's property you must check if it exists otherwise you may get a type error.
Thus in ES2020 we have ?. operator which does the job for you.

Alt Text

So when are you going to use optional chaining next?

Discussion

markdown guide
 

I didn't think I needed this till I recently discovered it. I now use it all the time.