&安培;&安培; Javascript中的运算符 [英] && operator in Javascript
问题描述
在查看一些代码(javascript)时,我发现了这段代码:
While looking through some code (javascript), I found this piece of code:
<script>window.Bootloader && Bootloader.done(["pQ27\/"]);</script>
我不明白的是&&&
正在那里,代码来自Facebook,显然是缩小和/或混淆,但它仍然做同样的事情。
What I don't understand is what the &&
is doing there, the code is from Facebook and is obviously minified and/or obfuscated, but it still does the same thing.
tl; dr: &&
运算符在这里做什么?
tl;dr: What does the &&
operator do here?
推荐答案
&&
确保 Bootloader
函数/对象在调用 done
方法之前就已存在。代码利用布尔短路来确保第一个表达式在执行第二个表达式之前求值为true。请参阅短路评估维基百科条目,以获得更深入的解释。
&&
makes sure that the Bootloader
function/object exists before calling the done
method on it. The code takes advantage of boolean short circuiting to ensure the first expression evaluates to true before executing the second. See the short-circuit evaluation wikipedia entry for a more in-depth explanation.
这篇关于&安培;&安培; Javascript中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!