Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda