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
msg
.includes()
hasWorld
undefined
Ohh yes thank you. I'll edit the snippet
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can actually take your code one step further:
If
msg
is undefined,.includes()
will never be called, andhasWorld
will beundefined
! One of my most awaited featuresOhh yes thank you. I'll edit the snippet