title: Explain how recursion works in an algorithm to determine depth of binary tree?
body: <p>I am new to data structures in JavaScript and am trying to learn Binary Search Trees.  I was following along with a blog post and was able to get a working solution to the problem of finding the max depth in a BST, but it's unclear to me how the recursion is working and how the +1 gets added on each time at each level of depth. What is a good way to think about this? Is it basically that each time the nodes value is not null, 1 gets added to what will eventually be returned up the call stack (i.e. at each level as it backtracks up to the root)?</p>
  
  <pre><code> function maxDepth(node) {
    // console.log(node.left);
    if (node) {
      return Math.max(maxDepth(node.left), maxDepth(node.right)) + 1;
    } else {
  
      return 0;
    }
  }
  </code></pre>