typescript declare variable undefined
let age: number | undefined;
age = 18;
if (age) {
// This will run because age is not null or undefined
}
age = undefined;
if (age) {
// This will not run because age is undefined
}
// If you want to do something when it is undefined
if (age === undefined) {
// This will run because age is undefined
}