title: Recursive function to scan to the DOM
body: <p>I'm reading Marijn Haverbeke's Eloquent Javascript. I come from a Flash/AS3 programming background but feel this book will be useful in getting me up to scratch fast. Below is the HTML and a JS snippet that scans the DOM for a match to see if a particular node has a given string:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;My home page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;My home page&lt;/h1&gt;
      &lt;p&gt;Hello, I am Marijn and this is my home page.&lt;/p&gt;
      &lt;p&gt;I also wrote a book! Read it
        &lt;a href="http://eloquentjavascript.net"&gt;here&lt;/a&gt;.&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  
  function talksAbout(node, string) {
    if (node.nodeType == document.ELEMENT_NODE) {
      for (var i = 0; i &lt; node.childNodes.length; i++) {
        if (talksAbout(node.childNodes[i], string))
          return true;
      }
      return false;
    } else if (node.nodeType == document.TEXT_NODE) {
      return node.nodeValue.indexOf(string) &gt; -1;
    }
  }
  
  console.log(talksAbout(document.body, "book"));
  // → true
  </code></pre>
  
  <p>I get functions, arrays, and the general syntax of course, but how does the following line work exactly. </p>
  
  <pre><code>if (talksAbout(node.childNodes[i], string))
          return true;
  </code></pre>
  
  <p>A general explanation if this function would be useful to me as it is not broken down into detail in the book. Thanks!</p>