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

前端 未结 30 1873
耶瑟儿~
耶瑟儿~ 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:53

    You can simply use the following (I know there are shorter ways to do this, but this may make it easier to visually observe, at least for others looking at the code).

    if (x === null || x === undefined) {
     // Add your response code here, etc.
    }
    

提交回复
热议问题