JavaScript check if value is only undefined, null or false

后端 未结 9 2065
暗喜
暗喜 2021-01-31 08:09

Other than creating a function, is there a shorter way to check if a value is undefined,null or false only in JavaScript?

9条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 08:18

    The best way to do it I think is:

    if(val != true){
    //do something
    } 
    

    This will be true if val is false, NaN, or undefined.

提交回复
热议问题