Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:10:12+00:00 2026-06-02T11:10:12+00:00

while (div.hasChildNodes()) { fragment.appendChild(div.firstChild) } while (div.firstChild) { fragment.appendChild(div.firstChild) } Comparing the two pieces

  • 0
while (div.hasChildNodes()) {
    fragment.appendChild(div.firstChild)
}

while (div.firstChild) {
    fragment.appendChild(div.firstChild)
}

Comparing the two pieces of pseudo code above, they both append each child of div to fragment until there are no more children.

  1. When would you favour hasChildNodes or firstChild they seem identical.
  2. If the APIs are so similar then why do they both exist. Why does hasChildNodes() exist when I can just coerce firstChild from null to false
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:10:16+00:00Added an answer on June 2, 2026 at 11:10 am

    a) micro-optimization!

    b) Although it seems to be common practice, I’m not fond of relying on null/non-null values being used as a substitute for false/true. It’s a space saver that’s unnecessary with server compression enabled (and can sometimes call subtle bugs). Opt for clarity every time, unless it’s demonstrated to be causing bottlenecks.

    I’d go for the first option, because it explains your intent perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with CSS with two divs. My first div contain texts while
I want to show a div with a loading animation over my page while
I would like to make one of the div's hidden while rendring. After page
<div id=container> some content </div> Say the container div is resizable, while resizing how
In the below code var panel= '<div id=title style=display:inline;font-size:150%;color:white;background:transparent;text-transform: none;width:150px;> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div> <div name=images id=name
I am using jquery to place an overlay over a div while I am
With the code below I add a DIV to the page, to which I
I use the following code to slide out a div on a mouse-over, wait
Here is my HTML code <div class=column> <div class=open></div> <div class=close></div> <div class=content> This
What will be the dojo equivalent code of following.? var msgContainer = document.createElement('div'); msgContainer.id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.