Unsure how this snippet works
<pre><code>var count = function(tree) {
    var stack = [];
    var count = 0;
    for (var node = tree; node; count++, node = stack.pop()) {
        if (node.left) stack.push(node.left);
        if (node.right) stack.push(node.right);
    }
    return count;
};
</code></pre>

<p>The above code works and returns the count of nodes within a binary tree.</p>

<p>I am confused as to how this works. Does <code>var stack = [];</code> not create an empty array?</p>

<p>If so, does node not become 0 when set within the for loop, thus making both if statements return false and not run?</p>

<p><strong>EDIT:</strong> I just realised the code <code>node = stack.pop()</code> will not be executed until the end of the loop body. Therefore node until that point will contain the current node passed into the procedure (Beginning with the head node). </p>

<p>Apologies for the mundane question, it's time for bed I think</p>
