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! While you're at it, check out some resources Treehouse students have shared here.
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 trialVic Mercier
3,276 Points|| operator
Can we use an or operator if we want to check if three values are true or it's just for two values?
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou can put as many as you want, like if a or b or c or d....would be true if any of a,b,c,d were true.
Lars Reimann
11,816 PointsThe || operator is a binary boolean operator. That's just a fancy way of saying that it takes two boolean values and merges them into one boolean value. Another binary operator you know is +. It takes two numbers and merges them into a new number. If you want to add three numbers, you just use + twice, like so: 1 + 2 + 3. You can either evaluate the left + first or the right + first, but you get the same result either way. The same is true for ||. If it is enough for you that one of three conditions is true, you just use || twice. And again it does not matter, if you evaluate the left one or the right one first.
Note that not all operators have this associative property. (1 - 2) - 3 is not the same as 1 - (2 - 3) for example. So use parenthesis if you are unsure.