if(eggsAmount < eggsMin || milkAmount < milkMin || flourAmount || FlourMin)
Does it mean whichever of these are true?
if(eggsAmount < eggsMin || milkAmount < milkMin || flourAmount || FlourMin)
Does it mean whichever of these are true?
Yes, in an if statement with only OR ||
operators, it will simply go through each condition and as soon as it finds one that is true, the if
statement resolves as true, the rest are not checked, and the code in the if
block.
An if statement containing multiple OR conditions (||
) has in Javascript the same behaviour descripted by Boolean Algebra: the whole evaluation is True
if any of the conditions is true.
At this w3schools link you can find JS logic operators description.
Anyway the evaluation of the expression itself is not necessarily a boolean value. The expression
Res = expr1 || expr2 || ... || exprN
is evaluated as the first condition that can be evaluated as true (for example if expr1
is 4+7
, Res=11
.
If none of the condition can be evaluated as true the assigned value is the value contained in the last condition: Res = exprN
.
(thanks to Jared Farrish, Barmar and Teemu)