In JavaScript, var declarations create properties on the global object:
var
var x = 15; console.log(window.x); // logs 15 in browser console.log(glo
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:
let
window