My question is quite simple, if I declare an IF statement with a series of OR clauses will JavaScript read all of the ORs or stop at the first one that is satisfied?
Thanks in advance.
My question is quite simple, if I declare an IF statement with a series of OR clauses will JavaScript read all of the ORs or stop at the first one that is satisfied?
Thanks in advance.
最初の 1 つで停止します。短絡といいます
http://en.wikipedia.org/wiki/Short-circuit_evaluation https://developer.mozilla.org/en/JavaScript/Reference/Operators/Logical_Operators
function foo() {
return true;
}
function bar() {
alert("bar");
}
foo() || bar(); // true - no alert
bar() || foo(); // true - alert of "bar"
true を返す最初の OR までのみ処理する必要があります。
if (a || b || c) {
}
aが偽、bが真、cが真の場合、bまで処理します。
最初の条件が満たされた場合、 の他の条件はor
評価されません