How to check undefined in Typescript

前端 未结 9 1163
面向向阳花
面向向阳花 2021-02-04 23:05

I am using this code to check undefined variable but it\'s not working.

9条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 23:49

    NOT STRICTLY RELATED TO TYPESCRIPT

    Just to add to all the above answers, we can also use the shorthand syntax

    var result = uemail || '';
    

    This will give you the email if uemail variable has some value and it will simply return an empty string if uemail variable is undefined.

    This gives a nice syntax for handling undefined variables and also provide a way to use a default value in case the variable is undefined.

提交回复
热议问题