DEV Community

Discussion on: Optional Chaining in Javascript

Collapse
 
kenbellows profile image
Ken Bellows

You can actually take your code one step further:

const hasWorld = response?.data?.msg?.includes('world')

If msg is undefined, .includes() will never be called, and hasWorld will be undefined! One of my most awaited features

Collapse
 
dhilipkmr profile image
Dhilip kumar • Edited

Ohh yes thank you. I'll edit the snippet