title: Javascript recursion with return statement and without
body: <p>Is there a difference between these two recursive functions? One with a return statement and one without it for the recursive calls. They both print numbers 1 - 8 in the console browser, my questions is whether there is some optimization happening under the hood when the recursion takes place with a return vs without one.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const solution = (input, i = 0) =&gt; {
    if (i === input) return // base case
    console.log(i)
    return solution(input, i + 1) // return recursive call
  }
  
  const solution2 = (input, i = 0) =&gt; {
    if (i === input) return // base case
    console.log(i)
    solution2(input, i + 1) // recursive call
  }
  
  console.log(solution(4))
  console.log("----")
  console.log(solution2(4))</code></pre>
  </div>
  </div>
  </p>