检查Javascript中是否存在值

时间:2010-12-23 21:59:27

标签: jquery

如何检查给定变量是否有值?什么是JS的等效PHP isset?

2 个答案:

答案 0 :(得分:1)

if (myVariable === undefined) {
    // myVariable has not been assigned a value...
}

此外,在Stackoverflow上询问并回答了同样的问题。 See, How can I determine if a JavaScript variable is defined in a page?

答案 1 :(得分:0)

if(typeof variable === "undefined") {
    //code here
}