Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!