title: How does recursion work in the example below?
body: <p>I am a beginner and I am trying to understand how recursion works in this function. More specifically, I am confused why <code>console.log('end: ' + i);</code> is being executed when <code>return;</code> should exit the function once the <code>(i &lt; 0)</code> condition is met. </p>
  
  <p>I've not found an explanation anywhere else, can someone explain to me?</p>
  
  <pre><code>function foo(i) {
    if (i &lt; 0)
      return;
    console.log('begin: ' + i);
    foo(i - 1);
    console.log('end: ' + i);
  }
  foo(3);
  // Output:
  
  // begin: 3
  // begin: 2
  // begin: 1
  // begin: 0
  // end: 0
  // end: 1
  // end: 2
  // end: 3
  </code></pre>