I'm currently exploring the concept of block scoping in ES6 and encountered an interesting issue that I need help understanding:
In my initial test, I attempted the following code snippet and observed the error mentioned within the comments:
{
const x = 2;
console.log( x ); //2
{
let x = "b";
console.log(x); //b
{
var x = true; //Identifier 'x' has already been declared
}
}
}
console.log(x)
Upon trying to determine the type of the previously declared x variable, I encountered something unexpected:
{
const x = 2;
console.log( x ); //2
{
let x = "b";
console.log(x); //b
{
console.log(typeof x); //this throws Uncaught ReferenceError: x is not defined
}
}
}
console.log(x);
I will continue investigating this issue to gain a deeper understanding. Any insights or suggestions are greatly appreciated.