Let Const TDZ
by IllusionMH
JavaScript
let log = (data) => document.body.innerHTML += `<pre>${JSON.stringify(data, null, ' ')}</pre>`
try {
//log(functionScope);
//log(blockScope); //"ReferenceError: blockScope is not defined"
//log(constantValue); //"ReferenceError: constantValue is not defined"
var functionScope = 1;
let blockScope = [1, 2, 3];
const constantValue = 2;
//let blockScope = 123; //"SyntaxError: Identifier 'blockScope' has already been declared"
//constantValue = 3; //"TypeError: Assignment to constant variable."
{
var functionScope = 123;
let blockScope = 123;
}
log(functionScope);
log(blockScope);
} catch (e) {
log(e.toString());
}