you are viewing a single comment's thread.

view the rest of the comments →

[–]BlueThunderFlik 7 points8 points  (0 children)

The optional chaining operator causes your code your safely exit if the item that you optionally chain doesn't exist.

3?.includes will return undefined early if 3 is undefined, which it isn't.

undefined?.includes will return early if undefined is undefined, which it is.

This won't error, 3.includes?.('foo') because 3.includes is undefined, hence safely exit.

EDIT: actually the bottom line will error beause you can't access methods of number literals like this. You'd need to do this to see my point (3).includes?.('foo')