DEV Community

Discussion on: What's new in JavaScript: Optional Chaining

Collapse
 
vedgar profile image
Vedran Čačić

What's the difference from simply writing a.b instead of a?.b? It still returns undefined if a is undefined, as far as I see.

Collapse
 
albertomontalesi profile image
AlbertoM

Actually if you try to access a property of undefined you will get an error Uncaught TypeError: Cannot read property 'b' of undefined

Collapse
 
vedgar profile image
Vedran Čačić

Interesting. I'm quite sure it didn't work that way the last time I tried JS, some 10 years ago. :-D