I started to learn JavaScript and I use Snippets or just Console in Google Chrome. I don't understand one thing. When I run snippet like:
let x = 5;
console.log(x);
multiple times. Everything is ok, but when I first run this:
var x = 5;
console.log(x);
and then I change the code to use let:
let x = 5;
console.log(x);
I get error SyntaxError: Identifier 'x' has already been declared
and I don't understand why.
I assume that variables declared with let are somehow "volatile", but variables declared with var are associated with window object, so they are "non volatile"?
Or in more general: are declarations in global environment's declarative environment record wiped out after script execution but declarations stored in global environment's object environment record are not?
When I run snippet in Google Chrome Snippets/Console multiple times, does it run in same Execution Context or it is recreated with new global environment each time when I push Run button?