Comparators and Order of Operations !()


#1

Introduction to Objects Lesson 1

The Hint is this lesson indicates that:

!(false && (!false)) = opposite of false AND not-false

Per order of operations wouldn't the outside ! operate on both Boolean statements? i.e.

!(false && (!false)) = !false && !!false = not false, and not-not false

How should I think about this?

 (((3 * 90) === 270) || !(false && (!false)) || "bex".toUpperCase() === "BEX");

The above comparison evaluates to true. I don't understand the comparison of the center statement.


#2

Per order of operations wouldn't the outside ! operate on both Boolean statements?

Exactly. But not in the way you described.

!(false && (!false)) = !(false && true) = !(false) = true

If you want to extend this expression (remove the negation) then you have to use De Morgan's laws:

!(p && q) = (!p || !q)

And that is why:

!(false && (!false)) = (!false || !!false) = (true || false) = true

(3 * 90) === 270 is true. And that is why we already know that the whole expression will evaluate to true. You don't have to check other parts :slight_smile:


#3

Thanks, that makes sense. Great answer, and so fast!


#4

You're very welcome :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.