javascript

 Optional chaining  allows us to access deeply nested properties values , without having to check whether the intermediate property exists or not. In Javascript Optional Chaining is represented by `?.` and this feature was introduced in ES2020


Let's understand this in detail. For an example consider  response object











Accessing a non-existed property will throw an Error.To avoid this error obvious solution would be to check the value using if or the conditional operator ? before accessing its properties as mentioned below
Code language: JavaScript (javascript)



As we can see the response.customer appears twice. For more deeply nested properties , that becomes a problem as more repetitions are required

Lets try accessing response.customer.address.street











Comments