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 Asynchronous Programming with JavaScript Understanding Promises Reject a Promise and Handle Errors

What's the point of initializing a variable to true, if we already know what the outcome will be? (fulfilled)

.

2 Answers

Tony Soukkeo
Tony Soukkeo
8,170 Points

It 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
Robert O'Toole
6,366 Points

i 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?

Same 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