title: Why is this recursive function exceeding call stack size?
body: <p>I'm trying to write a function to find the lowest number that all integers between 1 and 20 divide.  (Let's call this Condition D)</p>
  
  <p>Here's my solution, which is somehow exceeding the call stack size limit.</p>
  
  <pre><code>function findSmallest(num){
      var count = 2
      while (count&lt;21){
          count++
          if (num % count !== 0){
              // exit the loop
              return findSmallest(num++)
          }
  
      }
      return num
  }
  
  console.log(findSmallest(20))
  </code></pre>
  
  <p>Somewhere my reasoning on this is faulty but here's how I see it (please correct me where I'm wrong):</p>
  
  <p>Calling this function with a number N that doesn't meet Condition D will result in the function being called again with N + 1.  Eventually, when it reaches a number M that should satisfy Condition D, the while loop runs all the way through and the number M is returned by the function and there are no more recursive calls.  </p>
  
  <p>But I get this error on running it:</p>
  
  <blockquote>
    <p>function findSmallest(num){
                         ^</p>
    
    <p>RangeError: Maximum call stack size exceeded</p>
  </blockquote>
  
  <p>I know errors like this are almost always due to recursive functions not reaching a base case.  Is this the problem here, and if so, where's the problem?</p>