title: JavaScript: Too much recursion?
body: <p>I am learning JavaScript through <em>Eloquent JavaScript</em> and one of the exercises is to write a recursive function, <code>isEven</code>, that returns true if a number is even or false if a number is odd. </p>
  
  <p>If I understood correctly, the author specifically wanted the following to be implemented:</p>
  
  <ol>
  <li>If a number == 0, then it is even. </li>
  <li>If a number == 1, then it is odd. </li>
  <li>"For any number N, its evenness is the same as N-2".</li>
  </ol>
  
  <p>But when I use the code I have below, I get an error: <code>InternalError: too much recursion (line 3 in function isEven) …</code> How can I fix this while still using a recursive function? </p>
  
  <pre><code>// Your code here.
  function isEven(n){
    if(n==0){
      return true;
    }
    else if(n==1){
      return false;
    }
    else{ 
      n = n-2; 
      isEven(n);  
    }  
  }
  
  console.log(isEven(50));
  // → true
  console.log(isEven(75));
  // → false
  console.log(isEven(-1));
  // → ??
  </code></pre>