title: why use let replace var in recursion is better?
body: <p>when i try to do a LeetCode question # 25, use var can't pass, but use let can pass</p>
  
  <p>var</p>
  
  <pre><code>/**
   * Definition for singly-linked list.
   * function ListNode(val) {
   *     this.val = val;
   *     this.next = null;
   * }
   */
  /**
   * @param {ListNode} head
   * @param {number} k
   * @return {ListNode}
   */
  var reverseKGroup = function(head, k) {
      var p = head;
      var cur = head;
      var pre = null;
      for(var i=0; i&lt; k; i++) {
          // 如果里面没走到最后就结束，则直接返回这部分链表 不需要再反转
          if(p == null) return head;
          p = p.next;
      }
      // 反转部分链表
      for(var j=0 ; i&lt; k; i++) {
          var temp = cur.next;
          cur.next = pre;
          pre = cur;
          cur = temp;
      }
      // 此时的尾部即为一开始的头部，next 为接下来反转
      head.next = reverseKGroup(cur, k);
      return pre;
  };
  </code></pre>
  
  <p>the only difference is use "var" or "let".</p>
  
  <p>use var will cause an overflow.</p>
  
  <pre><code>Line 13 in solution.js
  var reverseKGroup = function(head, k) {
                              ^
  RangeError: Maximum call stack size exceeded
  </code></pre>
  
  <p>can somebody explain this ?</p>