JS判断undefined类型
if (currentIndex== null){
alert("null");
}
发现判断不出来,接着
if (currentIndex== undefined){
alert("undefined");
}
同样判断不出来
最后网上查了下要用typeof
if (typeof(currentIndex) == "undefined") {
alert("undefined");
}
typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
本文探讨了在JavaScript中如何准确地判断变量是否为undefined类型。通过实例演示,比较了使用'=='和'==='操作符的局限性,并介绍了使用typeof操作符进行类型检查的正确方法。
3万+

被折叠的 条评论
为什么被折叠?



