The Temporal Dead Zone, or why the TypeScript codebase is littered with var statements
October 1, 2025
If you have been working with JavaScript for a while, you probably know there are a couple of different ways to initialize a variable. Nowadays we usually use
const password = "hunter2"
and only occasionally, if you need some mutable state:
let password = "hunter2"
These declarations have been around for a while and they have reasonable block scoping rules:
function example ( measurement ) { console . log ( calculation ) ; console . log ( anotherCalc ) ; if ( measurement > 1 ) { const calculation = measurement + 1 ; let anotherCalc = measurement * 2 ; } else { } console . log ( calculation ) ; console . log ( anotherCalc ) ; }
But if you have been working with JS for a really long while, you might remember the time when neither of these declarations were possible. All we had was var . And var stinks. Not only is every variable mutable, with no way to enforce immutability, but to make matters worse, var leaks beyond block scope:
function example ( measurement ) { console . log ( calculation ) ; console . log ( i ) ; if ( measurement > 1 ) { var calculation = measurement + 1 ; } else { } console . log ( calculation ) ; for ( var i = 0 ; i < 3 ; i ++ ) { } console . log ( i ) ; }
... continue reading