Im new in javascript and in programming.
If I declare a variable with var
I see that my variable is declared globally and my variable is inside the window
object.
Example:
var element1 = 1;
window.element1; //This returns 1
But when I use let
I can't access my variable using the window object.
Example:
let element2 = 1;
window.element2; //This returns undefined
So, where has been my variable element2
been declared?
What is the scope of element2
?