I was going through the Difference between var
and let
documentation example and was testing that when an undeclared variable is invoked, the global scope automatically provides a declaration for it (that's why the following snippet does not throw an error in any of the variables):
x = 3;
console.log(x);
(function() {
y=x+39;
})()
console.log(y);
See Question&Answers more detail:os