[英]js conditional: if not false, null or undefined then
I have this !! 我有这个 !! markup for anther object and it works, but here it doesn't (in one case, works in other cases).
花药对象的标记,它可以工作,但在这里却无效(在一种情况下,在其他情况下有效)。
if (!!slides) {
console.log("close view clear slides")
clearInterval(slides);
}
In firebug I get this error: 在萤火虫中,我得到这个错误:
ReferenceError: slides is not defined
What should my conditional be? 我的条件是什么?
You can't use a variable if it's not defined. 如果未定义变量,则不能使用。
typeof(asdf)
"undefined"
!asdf
ReferenceError: asdf is not defined
if (typeof(asdf) != "undefined") {
// will only execute if asfd is defined.
}
Change 更改
if (!!slides) {
to 至
if (!slides) {
Though, if slides is false, null, or undefined, then clearing it wouldn't do anything. 但是,如果slides为false,null或undefined,则清除它不会做任何事情。 So, maybe what you mean is
所以,也许你的意思是
if (slides) {
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.