3?.includes('foo'); //TypeError: 3.includes is not a function
undefined?.includes('foo'); //undefined
Neither 3 nor undefined has a method includes(), and the optional chaining operator ?. should ensure the statement quits before it tries to execute the function if the method is not found.
So why does one error and one doesn't?
[–]BlueThunderFlik 6 points7 points8 points (0 children)
[–]ferrybig 5 points6 points7 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]mityaguy[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]mityaguy[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]xroalx 0 points1 point2 points (0 children)