namaste-javascript-notes

Episode 7 : The Scope Chain, Scope & Lexical Environment

// CASE 2
function a() {
    c();
    function c() {
        console.log(b); // 10
    }
}
var b = 10;
a();
// CASE 3
function a() {
    c();
    function c() {
        var b = 100;
        console.log(b); // 100
    }
}
var b = 10;
a();
// CASE 4
function a() {
    var b = 10;
    c();
    function c() {
        console.log(b); // 10
    }
}
a();
console.log(b); // Error, Not Defined



Watch Live On Youtube below:

The Scope Chain, Scope & Lexical Environment Youtube Link