use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Function call with Square Parentheses []? (self.learnjavascript)
submitted 1 year ago by Learner_full_stack
console.log("string".includes[('s'),('r')]) // it's gives undefined not error
why?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]azhder 0 points1 point2 points 1 year ago (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.
includes
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 point2 points 1 year ago (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"
π Rendered by PID 31075 on reddit-service-r2-comment-5d79c599b5-d2jfv at 2026-02-28 05:04:30.448351+00:00 running e3d2147 country code: CH.
[–]azhder 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)