Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda