javascript - Let Scope output -
can explain why first console in test function gives value 99.
let l = 99; function test(){ console.log(l); if(true){ let l = 7; console.log(l); } } test(); console.log(l);
added comments explanation
// global scope let l = 99; function test(){ // console.log(r); can't accessed here // can see global scope console.log(l); if(true){ // limited scope let l = 7, r=0; // l overides global scope console.log(l); } // console.log(r); can't accessed here } test(); // can see l in global scope console.log(l);
to learn scope of let please refer mdn blog
Comments
Post a Comment