title: Why childNodes[i] in function return undefined but alert an object?
body: <p>Well, i'm writting my own getElementByClassName and this is my problem :</p>
  
  <pre><code>function getElementByClassName(elemento,clase){
          var i = 0;
          if(elemento.hasChildNodes()){
              while(elemento.childNodes[i]){
                  if(elemento.childNodes[i].nodeType != 3){
                      if(elemento.childNodes[i].className == clase){
                          return elemento.childNodes[i];  // &lt;---- This is my problem, change to alert
                      }
                      else {
                      getElementByClassName(elemento.childNodes[i],clase);
                      }
                  }
  
                  i++
              }
          }
  }
  
  var div = getElementByClassName(document.body,"foo");
  
  alert(div);
  </code></pre>
  
  <p>It alerts undefined, but if i put ( in function) alert this alerts [objectHTMLDivElement] and undefined, so why this returns undefined if this recognize that's a [objectHTMLDivElement] with alert?</p>