While loop in parent function JavaScript
<p>I am having trouble interpreting what this code is doing.  Here it is:</p>

<pre><code>function parent(e, n) { 

    if (n === undefined) n = 1; //if n is not defined, use 1 by default

    while(n-- &amp;&amp; e) e = e.parentNode; 

    if (!e || e.nodeType !== 1) return null; 

    return e;   

}
</code></pre>

<p>This function accepts two arguments.  One for the element and the second for the ancestor of the element.  So, passing a 2 in the second argument would retrieve the grandparent of the element (2 elements up the DOM tree).  </p>

<p>I understand all of it, except for the <code>while</code> loop.  I am not sure how counting backwards is selecting that specific ancestor.  How does this while loop work making this function select an ancestor??</p>
