How to check 'undefined' value in jQuery

后端 未结 11 595
慢半拍i
慢半拍i 2020-12-12 11:49

Possible Duplicate:
Detecting an undefined object property in JavaScript
javascript undefined compare

H

11条回答
  •  不知归路
    2020-12-12 12:20

    In this case you can use a === undefined comparison: if(val === undefined)

    This works because val always exists (it's a function argument).

    If you wanted to test an arbitrary variable that is not an argument, i.e. might not be defined at all, you'd have to use if(typeof val === 'undefined') to avoid an exception in case val didn't exist.

提交回复
热议问题