Why, with this code, the first console.log() generates an error (surprise, because I thought this behavior was only with var
, not let
):
(function() {
"use strict";
let i=12;
function test() {
console.log(i);
let i=4544444;
console.log(i);
};
test();
})();
do I get:
Uncaught ReferenceError: i is not defined
? Moreover, if I comment those lines:
(function() {
"use strict";
let i=12;
function test() {
console.log(i);
//let i=4544444;
//console.log(i);
};
test();
})();
Then it works (I thought with "use strict"
you cant have variables with the same name at the same time)