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

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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