Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript; parsing an IF statement with OR clauses

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.

like image 304
David Smythe Avatar asked Dec 09 '25 15:12

David Smythe


2 Answers

Stops at the first one. It's called short-circuiting

http://en.wikipedia.org/wiki/Short-circuit_evaluation https://developer.mozilla.org/en/JavaScript/Reference/Operators/Logical_Operators

like image 189
davin Avatar answered Dec 11 '25 05:12

davin


It should only process upto the first OR that returns true:

if (a || b || c) { 

}

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

like image 44
Lloyd Avatar answered Dec 11 '25 04:12

Lloyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!