Get rid off null checks in Javascript 2019

ManiCibi CS
Mar 20 · 1 min read

When I tried to update my knowledge on javascript, I have gone through a wonderful thing in javascript.

Have you ever had the problem of accessing nested object property, something like this?

Doing this way is tedious in case of complex data structures. To get rid of this, javascript is introducing a new concept call optional chaining and works as follows.

optional chaining in javascript

this makes more easy, readable and simple. isn’t it?

Note: Currently, optional chaining is not part of the official spec, but is at stage-1 as an experimental feature. You have to add @babel/plugin-proposal-optional-chaining in your babelrc to use it.