Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Understanding Javascript String.prototype.includes() when dealing with empty string

Could anyone tell me how it prints "got" when the string does not contain empty string at all?

const sentence = "Depreciation";

if(sentence.includes("")){
 console.log("got"); 
}
else{
 console.log("none"); 
}

Js string.includes()

I was doing a project where I was supposed to filter a loaded with data array variable content based on the user's input in the search box. Surprisingly, when the user does not input anything (empty string), it returns the original(full) content of the array instead of an empty array. I was using array.filter() and string.includes().

I understood array.filter as it will return a new array which fulfills the condition written inside the filter function, which is the string.includes(). That said, I thought it is supposed to return empty array since the array content itself does not has any element contains empty string.

That leads me to the question asked, any of your help will be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!