Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 776 Bytes

operator_precedence.md

File metadata and controls

28 lines (21 loc) · 776 Bytes

Operator Precedence

The operators that work on booleans have a "precedence order."

This defines an order of operations similar to mathematics, where multiplication and division happen before addition and subtraction.

For booleans ! always happens first. This is followed by && and then by ||.

booleana = true; booleanb = false; booleanc = false; // just as 2 + 5 * 3 "evaluates" 5 * 3 before adding 2// first, !b is true// second, a && true is true// third true || c is true.booleanresult = a && !b || c;

Also like mathematics, parentheses can be used to control this order.

// Even though || has a lower precedence than &&, we evaluate// !b || c first because of the parentheses.booleanresult = a && (!b || c);
close