FAQ: Conditionals and Control Flow - Boolean Operators: Precedence

#1

This community-built FAQ covers the “Boolean Operators: Precedence” exercise from the lesson “Conditionals and Control Flow”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Boolean Operators: Precedence

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#2

Though there’s an order to the boolean, equation in parentheses come in first right? The computer will read !(3<4 || (5>7 && 6<8)); as false.

#3

I’m confused how the order of operations happens in the example: (!(false) || true && false)
The way I see it the order goes !(false) evaluates to true, turning the equation into (true || true && false), which should then go true || true returns true, and then true && false returns false. So why is the && evaluated before the ||?
I even tested it out in the console by just running System.out.println(true || true && false), which if we’re going left to right should return false, but instead returns true. Can someone explain why that is to me?

#4

Because they are part of the same clause, AND is evaluated first, then OR. Not that it matters, in this instance since OR short-circuits on true.

``````(!(false) || true && false)
``````

We can safely remove the outer brackets since it contains essentially a single clause (i.e., expression).

``````!(false) || true && false
``````

NOT will affect only the adjacent expression, and as it is at the top of the precedence chain we can evaluate it first.

``````true || true && false
``````

AND takes precedence to OR, so we have,

``````true || false
``````

As mentioned, this is all moot since OR will ignore any operands after a true. The above is true, regardless what was on the right side of OR.

#5

Thank you! That’s definitely good to know. The instructions only said that everything gets operated from left to right (after parentheses) so this distinction was not made clear.