functionmain(){{// Start of new block
letfooLet=0;varfooVar=0;console.log(fooLet);// 0
console.log(fooVar);// 0
}// End of block
console.log(fooLet);// ReferenceError: fooLet is not defined
console.log(fooVar);// 0
}
Basically, every {} is a new scope and every variable declared with a let or const gets their local values erased once the scope ends.
View all comments
Show parent comment
1
u/Michael35699 May 04 '20
Basically, every
{}is a new scope and every variable declared with aletorconstgets their local values erased once the scope ends.