Consider the code below which I am running in my chrome browser console:
var x = "hello";
let foo =  function(){
  console.log("hi");
};
console.log(x); // hello
console.log(foo()); //hi
console.log(window.x); // hello
console.log(window.foo()); // Error
If I had used var foo =... instead of let foo = .. then this would have worked. Why ? 
 
    