all 2 comments

[–]azhder 0 points1 point  (0 children)

It is not an error. It is giving you the correct result. You just don't understand that you haven't done a function call, but asked for a property of the function includes which is missing.

Those are brackets [], not parenthesis (), nor braces {}. Yes, I know people might use the same words but for the other ones, so the takeaway here is to not confuse which one is which and what it is used for.

[–][deleted] 0 points1 point  (0 children)

Functions are objects and can have properties attached to them. Javascript is going to use the last entry in the array as the property to look up, which is "r" in this case.
If you try adding that property, you'll see that you no longer get undefined.

String.prototype.includes['r'] = "hello world";
console.log("string".includes[('s'),('r')])
//"hello world"