简体   繁体   English

浏览器对Javascript中的简写空/未定义检查有什么支持?

[英]What's the browser support for a shorthand null/undefined check in Javascript?

A few years ago I remember using something like this in some Javascript: 几年前,我记得在某些Javascript中使用了以下内容:

someFunc(someVar || 42);

...as a shorthand in case someVar is null or undefined. ...作为someVar为null或未定义的简写形式。 I vaguely remember IE 8 choking on this. 我隐约记得IE 8在这方面令人窒息。 Maybe I'm remembering incorrectly, so can anyone confirm or deny browser support issues with this type of Javascript statement? 也许我记错了,所以有人可以确认或拒绝这种Javascript语句对浏览器的支持问题吗?

I don't have access to IE 8 at the moment so I can't test it myself. 我目前无法访问IE 8,因此无法自己进行测试。 Also, if this question isn't a duplicate, then it might be useful to others. 另外,如果这个问题不是重复的,那么对其他人可能也会有用。 Lastly, is there a name for this type of conditional statement? 最后,这种条件语句是否有名称?

这种事情在IE 10中运行。如果IE 8是硬性要求,您可以做的是三元运算符:

funcCall(someVal ? someVal : 42)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM