Do let statements create properties on the global object?

前端 未结 5 720
囚心锁ツ
囚心锁ツ 2020-11-22 01:11

In JavaScript, var declarations create properties on the global object:

var x = 15;
console.log(window.x); // logs 15 in browser
console.log(glo         


        
5条回答
  •  执笔经年
    2020-11-22 01:51

    Both let and var variables, if declared at the top-level of a script, are accessible outside of the script file. However, only var variables get assigned to the window object. Have a look at this code snippet as proof:

    
    
    

提交回复
热议问题