typescript declare variable undefined

Solutions on MaxInterview for typescript declare variable undefined by the best coders in the world

showing results for - "typescript declare variable undefined"
Lionel
31 Nov 2019
1let age: number | undefined;
2age = 18;
3
4if (age) {
5  // This will run because age is not null or undefined
6}
7
8age = undefined;
9
10if (age) {
11  // This will not run because age is undefined
12}
13
14// If you want to do something when it is undefined
15if (age === undefined) {
16  // This will run because age is undefined
17}
Melyna
30 Jul 2020
1let name1:string = person.name!; 
2//                            ^ note the exclamation mark here  
3