Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Booleans Ruby Booleans Precedence

Nicole Archambault
Nicole Archambault
27,852 Points

[SOLVED] Not understanding why "1 && 2 == 1 && 2" evaluates to "false"

I don't know why this just blew my mind... it might have something to do with the fact that it's 5:30 AM and I'm on Treehouse, though.

The video transcript states that 1 && 2 == 1 && 2 evaluates to false, because it compiles as 1 && (2 == 1) && 2.

How? Why? What? TIA!

EDIT: It was definitely because it's 5:30 AM. From the teacher's notes, I see now that it's actually evaluating it as 1 && false && 2, because it's grouping the logic operators incorrectly ( == has precedence over &&). If anyone else missed this, hopefully that helps!