How to check undefined in Typescript

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

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

9条回答
  •  半阙折子戏
    2021-02-04 23:45

    It's because it's already null or undefined. Null or undefined does not have any type. You can check if it's is undefined first. In typescript (null == undefined) is true.

      if (uemail == undefined) {
          alert('undefined');
      } else {
          alert('defined');
      }
    

    or

      if (uemail == null) {
          alert('undefined');
      } else {
          alert('defined');
      }
    

提交回复
热议问题