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 From Callbacks to Promises

why did he not use setTimeout() in the promise?

just so i understand, is the if condition of xhr.status === 200 where it determines if the promise is fulfilled? is the setTimeout() not the better method to use.

1 Answer

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

setTimeout is kind of an imitation of a promise. It fulfills your task after a certain time that you set up. Normally you use it just for test or demonstration purpose how promises work. Promise itself can be fulfilled or rejected only after its resolved. You don't assign it any times by yourself.