I am new to ECMAScript 2015(ES6) and I am reading about temporal dead zones in ES6:
if(typeof x === "undefined") {
console.log("x doesn't exist or is undefined");
} else {
// safe to refer to x....
}
let x = 5; //script.js:1 Uncaught ReferenceError: x is not defined
Obviously in ES6 if you test a variable with typeof before declaring it throws errors
console.log(typeof x);
let x = 5; //script.js:1 Uncaught ReferenceError: x is not defined
Why is this happening? Is this a bug?