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 trialvamosrope14
14,932 PointsWhat's the point of initializing a variable to true, if we already know what the outcome will be? (fulfilled)
.
2 Answers
Tony Soukkeo
8,170 PointsIt can be helpful, if you want to hide or display a certain element based on its Boolean value.
For example, on a webpage, I want to initially show an element to the user, so I would have a variable, let’s say showElement, set to true. And You can have a button, that if a user were to click on, it would set the showElement to false, thus hiding the element.
Robert O'Toole
6,366 Pointsi see here we are doing a test with simple examples like if (order){ resolve('string')}
in most cases what would the test condition look like?
i know with ajax its something like if(xhr.state==200&&xhr.readyState==4) to test if the request was sent ok. but in these cases im a bit confused?
Zoltán Erkel
6,340 PointsSame here so far. It's also somewhat irritating that (based on other comments from the community) one can't check the code as it can't be executed the same way as in the Visual Code terminal.
However based on the examples so far it seems like in contrast to AJAX readystate and state check, we for some reason provide the outcome. Sure this will be cleared along the way though.
UPDATE: to be fair it's probably just easier to model how promises work with passing a boolean to it