JavaScript的let作用域 和 JavasScript算法与数据结构


#1

最近在leetcode用JavaScript 刷题,碰到了一点不懂的,希望大家点拨一下

var addTwoNumbers = function(l1, l2) {
  let p1 = l1
  let p2 = l2
  let carry = 0
  const dummy = new ListNode()
  let pointer = dummy
  while (p1 || p2 || carry) {
    const num1 = p1 ? p1.val : 0
    const num2 = p2 ? p2.val : 0
    const sum = num1 + num2 + carry
    if (sum > 9) {
      pointer.next = new ListNode(sum % 10)
      carry = 1
    } else {
      pointer.next = new ListNode(sum)
      carry = 0
    }
    if (p1) p1 = p1.next
    if (p2) p2 = p2.next
    pointer = pointer.next
  }
  return dummy.next
};

//作者:hen-ji-shi
//链接:https://leetcode-cn.com/problems/add-two-numbers/solution/js-ya-jie-dian-by-hen-ji-shi/
//来源:力扣(LeetCode)
//著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

我的问题如下
let 的块级作用域并不影响他的本地作用域,那么他是如何改变dummy的?为什么是输出dummy.next而不是dummy?