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); } Terrible! So it was a big surprise to me to find out that the TypeScript codebase (which is itself written in TypeScript — for now ) is littered with var statements like it's 2003 : export function createSourceMapGenerator( host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions ): SourceMapGenerator { var { enter, exit } = generatorOptions.extendedDiagnostics ? performance.createTimer("Source Map", "beforeSourcemap", "afterSourcemap") : performance.nullTimer; var rawSources: string[] = []; var sources: string[] = []; var sourceToSourceIndexMap = new Map<string, number>(); var sourcesContent: (string | null)[] | undefined; var names: string[] = []; var nameToNameIndexMap: Map<string, number>...
First seen: 2025-10-03 20:54
Last seen: 2025-10-04 12:57