DEV Community

Discussion on: 😲🤯The most outstanding new feature in Javascript you need to know about: Optional Chaining

Collapse
 
svitekpavel profile image
Pavel Svitek

You are retrieving some data from API. Till you retrieve the data, you should have something like data: null, after you get data from API, you should have the whole object.

API should always return you a predefined object structure, right? So once data !== null, you should be able to access all properties and deep properties instead of checking every object in your structure.

I understand that there might be some valid cases where object?.property?.property might be a shorter code, but it doesn't mean it should be implemented in the language.

Once this is in language, the syntax will be overused and more shitty code will be written.

Thread Thread
 
lampewebdev profile image
Michael "lampe" Lazarski

What if the API is not in your hand and you have no control over it?

I don't see it being overused in ruby or c# or any other language. Why should this happen in JS?

Thread Thread
 
sudojoe profile image
Joseph Locke • Edited

Assuming that objects returned from third-parties conform to a specific structure (and therefore, not 'verifying' their structure and the presence/lack-thereof of expected properties) is most-likely a security blunder.

Thread Thread
 
lampewebdev profile image
Michael "lampe" Lazarski

Sorry, I don't fully understand what you mean.