Optional Chaining is one of the newest features in JavaScript. This feature may seem insignificant. However, it can save you a lot of time, code and also a lot of headaches. In this tutorial, you will learn what this feature is about, how it works and how to use it to write better JavaScript code.

Defying the problem

Have you ever worked with objects? Then, you know how easy it is to run into following problem. Let’s say you have an object. This object has some properties and maybe also some methods. Next, let’s say that you want to work with some of these properties or methods.

Getting this done is very simple. You can access any property using either dot or square bracket notation. The same applies to methods. What happens is if you try to access some property, or method, that doesn’t exist in that object? When you try to access property that doesn’t exist you will get undefined.

#javascript #development #programming #web development

Optional Chaining in JavaScript and How It Works
2.20 GEEK