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

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

    I've just had this problem i.e. checking if an object is null.
    I simply use this:

    if (object) {
        // Your code
    }
    

    For example:

    if (document.getElementById("enterJob")) {
        document.getElementById("enterJob").className += ' current';
    }
    

提交回复
热议问题