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 The Solution

Difference between <5 and <=4

My solutions were almost identical to the instructor’s except I only used “greater than” or “less than” operators and no “greater/less than or equal to” operators. Based on the solutions provided it seems that in these particular cases they can be used interchangeably. For example on whileLoops solution 1 “i < 5” is used and in solution 2 “i <= 5” is used. In these cases “i <= 4” and “i < 6” respectively could also have been used. My question is, in cases like these, does it make any practical difference which operator is used? Is either alternative considered best coding practice?

1 Answer

Ignacio Rocha
Ignacio Rocha
7,462 Points

You are right both options work just fine there is no big difference and neither one is better than the other and there is no "Best practice" regarding these operators. Is good to know just the logic that you, as a developer, wants to implement in your code, if you understand what it does then both options are correct.