If I have this equation:
var x = (true && false || true)
Is that equivalent to:
var x = ((true && false) || true)
or:
var x = (true && (false || true))
And whats the logic behind this?
AND wins over OR.
So it will be
var x = ((true && false) || true)
See Operator precedence and associativity.
In boolean logic, "not" (!) is evaluated before "and" (&&) and "and" is evaluated before "or" (||). By using the double (&&) and the double (||), these operators will short circuit, which does not affect the logical outcome but it causes terms on the right hand side to not be evaluated if needed.
Thus
var x = (true && false || true) evaluates to false|| true which evaluates to true
and
var x = ((true && false) || true) evaluates to false || true which evaluates to true
and
var x = (true && (false || true)) evaluates to true && true which evaluates to true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With