JavaScript parsing IF statements with OR clauses

My question is quite simple, if I declare an IF statement with a series of OR clauses, will JavaScript read all ORs or dwell on the first satisfying one?

Thanks in advance.

+3
source share
4 answers

It should only process the first OR, which returns true:

if (a || b || c) { 

}

If a is false, b is true, and c is true, it will process to b.

+1
source
function foo() {
    return true;
}

function bar() {
    alert("bar");
}

foo() || bar(); // true - no alert
bar() || foo(); // true - alert of "bar"
+1

, or

0

Source: https://habr.com/ru/post/1790444/


All Articles