如何检查给定变量是否有值?什么是JS的等效PHP isset?
答案 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
}