Exploring Lexical Scope in Javascript


JavaScript uses lexical scoping, meaning that functions are executed using the variable scope that was in effect when they were defined, not when they are invoked.

Source Code

let a = 'global';
function outer() {
  let b = 'outer';
  function inner() {
    let c = 'inner';
    console.log(c); // inner
    console.log(b); // outer
    console.log(a); // global
  }
  inner();
}
outer();
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments