0

When we use the var keyword outside of a function, it creates a global variable and attaches that global variable to window object in the browser. In contrast, when we use a let keyword to declare a global variable, that global variable is not attached to the window object. Then, where does the global variable declared by let keyword go?

Kinta
  • 57
  • 1
  • 6
  • 1
    let is not globally scoped as far as my understanding goes. You can find more detail here: https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var – ahsan Jun 10 '21 at 06:00
  • Kindly refer https://www.youtube.com/watch?v=BNC6slYCj50&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=9 for better clarity, even you can refer the whole tutorial for core javascript concept, you will thank me later – Amit Bisht Jun 10 '21 at 06:04
  • Chapter 2 in [@T.J.Crowder](https://stackoverflow.com/users/157247/t-j-crowder) 's [JavaScript, The New Toys](https://amzn.to/3csycQL) is also explaining this in great detail – mplungjan Jun 10 '21 at 06:06

0 Answers0