rb's blog

Scope/Lexical environment in javascript

jsscopelexical environment

Scope is directly depended on the lexical environment of a variable.

Lexical means presence in hierarchy. Lexical environment is created everytime a execution context is created.

Lexical environment is the local memory environment and the lexical environment of the parent.

  function a()  {
console.log(b); // prints 10
}
var b = 10;
a();
  function a()  {
var b = 10;
c();
function c() {
console.log(b) // prints 10
}
}
a();