Checking if a variable exists in javascript

后端 未结 7 1139
Happy的楠姐
Happy的楠姐 2021-01-31 06:58

I know there are two methods to determine if a variable exists and not null(false, empty) in javascript:

1) if ( typeof variableName !== \'undefined\' && v

7条回答
  •  清酒与你
    2021-01-31 07:56

    I found this shorter and much better:

        if(varName !== (undefined || null)) { //do something }
    

提交回复
热议问题