I would like to understand the following TypeScript behavior:
The following code
let a: number
if (a === undefined) {
console.log("how?")
}
throws an error: "Variable 'a' is used before being assigned.".
But the following code
let a: number
const f = (): void => {
if (a === undefined) {
console.log("how?")
}
}
f()
works just fine and logs "how?".
Why is that? And also, how come a === undefined if its type is number?