In real life we see the same 3 states and actually communicate in promises far more often than we might think. Going to my favorite bodega for a delicious chicken cutlet sandwich I place the order “On a roll, no cheese, no tomato, with lettuce, mayo, and hot-sauce.” My local homie behind the counter makes a promise to return the chicken sandwich just as I ordered. My promise is now pending while the sandwich is being made until it is fulfilled/settled with all the correct instructions or rejected for having cheese or tomato on top.
In the real world I have the ability to shower praise or anger upon someone making my precious bodega sandwich but in JS a returned promise is directly linked to two key words to handle the returned promise. .then and .catch.
Another great attribute of promises is that they are chain-able and the returned results of one promise are then passed on to the next promise in the chain. The most frequent example of this are the two .then promises returned from our fetch get request.
The fetch request returns our first promise object which we call .then on (r => r.json()). That call returns a new promise2 object , our response, which we chain with an additional .then on (toyData => renderAllToys(toyData)). The second .then gives us access to the body: ReadableStream which holds the toyData returned from the database. Chaining promises also allows us to structure promises in a synchronous way, where a list of promises run in line with each other and the promise2 cannot begin until promise1 has been returned. Also a single .catch can be used to and will handle any errors that are thrown if one of the previous promises are rejected