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

353
Visualizações
How come while (myNode.lastElementChild) works without any value?

Im learning JS by analyzing a to-do list tutorial and I'm stuck trying to fully understand the functions that clears a populated list by clicking a button. I think I understand this small script but not sure.

    `function clearTaks(){
        while(taskList.firstChild){
            taskList.removeChild(taskList.firstChild);
        }`

I think that the condition while(taskList.firstChild) means that meanwhile taskList still has a Chidren, keep doing... but I wonder why that works without any other value. I mean, shouldn´t it be something like this?: while(taskList.firstChild != false) or something similar. Thanks in advance for your help

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

taskList.firstChild is coerced to a boolean.

firstChild will return null if there is no child, which is Falsy (thus you will get false and the loop will terminate).

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