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

前端 未结 30 1526
耶瑟儿~
耶瑟儿~ 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 04:10

    You can use the qualities of the abstract equality operator to do this:

    if (variable == null){
        // your code here.
    }
    

    Because null == undefined is true, the above code will catch both null and undefined.

提交回复
热议问题