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

119
Vistas
Getting undefined with strict equality operator but not with normal equality operator
function sym(...args) {
  let arr = [...args];

  while(!arr.length === 0) {
      arr.pop();
      console.log(arr.length);
  }
}

console.log(sym([1,2,5],[2,3,5],[3,4,5]));

I was trying to figure one problem out but another problem came up. Can someone please explain to me why this logs undefined? The strict equality operator logs undefined but the normal equality operator doesn't, even though arr.length returns a number.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

! has higher operator precedence than ===.

while(!arr.length === 0) {

is equivalent to

while((!arr.length) === 0) {

Comparing a boolean to a number will never work with ===, but it will sometimes work with == - but either way, that isn't what you want. Use !== 0 instead.

function sym(...args) {
  let arr = [...args];

  while(arr.length !== 0) {
      arr.pop();
  }
  return arr;
}

console.log(sym([1,2,5],[2,3,5],[3,4,5]));

about 4 years ago · Juan Pablo Isaza Denunciar
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