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 trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Combining Multiple Tests Into a Single Condition

Some incorrectish info in the video. If(a || b){} != if(b||a){}, same for &&.

There was a suggestion that this, "If(a || b){} == if(b||a){}", was the case in the video.

In the case of an OR, if the left part is true, then the right part won't be checked at all by the program, because if one part is true the entire thing is true. This can be quite handy for numerous reasons, for example if one of the two checks takes a lot of computational time.

The same is true for AND, except the left part needs to be false. One part is false, the entire thing is fale.

1 Answer

Steven Parker
Steven Parker
231,248 Points

From the standpoint of executing the code block, the order of the items being ORed isn't important. So in that sense, the video is correct.

But you're also correct that there might be a difference if the evaluation itself is not idempotent (if it has some side-effect). The result of the first evaluation will determine if the second evaluation takes place at all. However, this issue does not apply to any of the simple examples shown in the video.