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

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

    jQuery attr() function returns either a blank string or the actual value (and never null or undefined). The only time it returns undefined is when your selector didn't return any element.

    So you may want to test against a blank string. Alternatively, since blank strings, null and undefined are false-y, you can just do this:

    if (!EmpName) { //do something }
    

提交回复
热议问题