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 trialKristine Zakaite
2,236 PointsWhy the code doesnt execute on false condition?
Hi there,
I cant fully get it, why, if while loop is set to condition false, it wouldnt execute the code block, since the condition is indeed false? How do we know that it is NOT false in this case? there is no variable above or any other info.
The code: while (false) { console.log('Hello'); } console.log('Goodbye');
Thank you.
1 Answer
Steven Parker
231,210 PointsThe code while (false)
is not testing anything to check the result, it has been given a literal "false" instead of a test. So that means it's never true and you can be certain that the code block will not run.
Clearly, this is only to check your understanding and is not something that would ever be done in real code.
Kristine Zakaite
2,236 PointsKristine Zakaite
2,236 PointsThank you !