php isset() equivalent in javascript

后端 未结 3 1135
后悔当初
后悔当初 2021-01-06 02:32

I\'m looking for the javascript equivalent of the php function isset(). I\'ve tried the method described here at JavaScript isset() equivalent but at firebug, e

3条回答
  •  醉酒成梦
    2021-01-06 03:11

    isset() makes two checks: first if the variable is defined, and second if it is null.

    You will have to check for both the 'undefined' case and the null case, for example:

    if (typeof data !== 'undefined' && data !== null)

提交回复
热议问题