0

According to scope chain inner functions can access to outer functions, but at the same time we are accessing outer function through closure, then what is difference? Can anyone explain differences between scope chain and closure? My version is that scope chain is just a rule and closure is explanation of how this rule works.

Question is about differences between Scoping and Closure

function outer() {
  a = 10;
   function inner() {
    b = 10;
    console.log(a + b);
  };
  return inner()
}

console.log(outer());  //logs: 20
Leonardo
  • 61
  • 4
  • 1
    Closure just emphasizes more, that the inner function actually remembers the scope it was created in, e.g. when you return the function, and call it in some other scope. – ASDFGerte Nov 17 '20 at 13:53
  • That is not a useful demonstration of a closure. `return inner`; `outer()()` would demonstrate it better… – deceze Nov 17 '20 at 13:54

0 Answers0