0

Let is block scope . But I have found this codes output wired. how the let declared in window can be accessed in another function?

let wind ="something blah blah";
function trial(){
console.log(wind);
}
trial();
  • Because that function is *also* in the same scope. It would be pretty limiting if functions couldn't access anything outside of themselves... – David Oct 19 '22 at 13:02
  • It is defined in the outer scope. So it is accessible from the function. – Eldar Oct 19 '22 at 13:02
  • see this for discussion of variable scope https://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript – Paul Crozer Oct 19 '22 at 13:02

0 Answers0