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,951 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.