title: Weird behavior of trampolining
body: <p>Recently I've been doing some JS tasks on codewars and encountered this task <a href="https://www.codewars.com/kata/53d045892578b1be8b0001c4" rel="nofollow noreferrer">Tail recursion with trampoline</a>.
  Here we need to create thunk function and trampoline function in order to get rid of annoying 
  <em>RangeError: Maximum call stack size exceeded</em>.
  So i tried this code:</p>
  
  <pre class="lang-js prettyprint-override"><code>function thunk(fn) { 
    let args = [...arguments].slice(1, arguments.length);
    return function () { 
      return fn.apply(null, args);
    };
  };
  
  function trampoline(thunk) {
    while (typeof thunk === 'function') {
      thunk = thunk();
    }
    return thunk; 
  }
  
  function isEven(n) {
    let arg = n;
  
    function _isEven() {
      return (arg === 0 ? true : isOdd(arg - 1));
    };
  
    return trampoline(thunk(_isEven, n));
  }
  
  function isOdd(n) {
    let arg = n;
  
    function _isOdd() {
      return (arg === 0 ? false : isEven(arg - 1));
    };
  
    return trampoline(thunk(_isOdd, n));
  }
  </code></pre>
  
  <p>And this didn't work, there still was RangeError.
  But after i added console.log() to _isOdd or _isEven it doesn't throw error and passes all the tests. Like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>function thunk(fn) { 
    let args = [...arguments].slice(1, arguments.length);
    return function () { 
      return fn.apply(null, args);
    };
  };
  
  function trampoline(thunk) {
    while (typeof thunk === 'function') {
      thunk = thunk();
    }
    return thunk; 
  }
  
  function isEven(n) {
    let arg = n;
  
    function _isEven() {
      console.log();
      return (arg === 0 ? true : isOdd(arg - 1));
    };
  
    return trampoline(thunk(_isEven, n));
  }
  
  function isOdd(n) {
    let arg = n;
  
    function _isOdd() {
      return (arg === 0 ? false : isEven(arg - 1));
    };
  
    return trampoline(thunk(_isOdd, n));
  }
  </code></pre>
  
  <p>I understood mistake and rewrote the code, but haven't understood why does it work when I add console.log().</p>