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.
So when are you going to use optional chaining next?
Top comments (2)
I didn't think I needed this till I recently discovered it. I now use it all the time.
pretty useful thing