FAQ: Logical Operators and Compound Conditions - The Not Operator

This community-built FAQ covers the “The Not Operator” exercise from the lesson " Logical Operators and Compound Conditions".

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

Learn PHP

FAQs on the exercise The Not Operator

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 (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.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

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

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

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!


I’m a bit confused about

!10 < 11; // Evaluates to: TRUE
!(10 < 11);  // Evaluates to: FALSE

in the explanations. I think understand the 2nd line. (10<11) is TRUE, so !(TRUE) is FALSE.

But how does the first line !10<11 evaluate to TRUE?

I do understand that the point of the examples was to show that “The not operator has very high operator precedence; be sure to use parentheses so that code evaluation happens as intended:” and that we should use parentheses like the 2nd line…

Thanks in advance!

As you correctly stated !(10 < 11); evaluates to FALSE because the comparison between the two integers 10 < 11 results in TRUE and therefore !(TRUE) evaluates to FALSE.

I think the statement !10 < 11; has to do with the NOT operator as well as type juggling. If we look at the documentation for comparison operators, the description for the less than operator mentions type juggling (if necessary).

The statement !10 < 11; can be thought of as (!10) < 11;.
10 is an integer. When we apply the NOT operator to the integer 10, we expect a boolean result. 10 is truthy (see the previous lesson https://www.codecademy.com/courses/learn-php/lessons/booleans-and-comparison-operators/exercises/truthy-and-falsy), so !10 results in !(TRUE) i.e. FALSE.

This means the statement !10 < 11; becomes FALSE < 11;. Since we have a comparison between a boolean type and an integer type, so type juggling happens. A boolean TRUE is juggled as the integer 1 while the boolean FALSE is juggled as the integer 0.

Therefore, the comparison FALSE < 11; becomes 0 < 11; (after type juggling) which evaluates to TRUE.