I have heard about shadowing in JS. My question is why can't we shadow a let variable present in global scope with a var variable present inside a block . Eg->
let a =100;
{
var a =100;
console.log(a);
}
- Output:-Uncaught SyntaxError: Identifier 'a' has already been declared.
This question came to my mind because I studied that let and var variables are present in different memory locations. So according to me this shouldn't be a problem.
And if there is a problem then why the below code is working
var a = 100;
{
let a=10;
console.log(a);
}
Output:- 10
Please provide a detailed answer explaining about the exceution context and variable environment in each case .