How can I determine if a variable is 'undefined' or 'null'?

前端 未结 30 2125
耶瑟儿~
耶瑟儿~ 2020-11-22 03:30

How do I determine if variable is undefined or null?

My code is as follows:

var EmpN         


        
30条回答
  •  忘掉有多难
    2020-11-22 03:55

    In JavaScript, as per my knowledge, we can check an undefined, null or empty variable like below.

    if (variable === undefined){
    }
    
    if (variable === null){
    }
    
    if (variable === ''){
    }
    

    Check all conditions:

    if(variable === undefined || variable === null || variable === ''){
    }
    

提交回复
热议问题