It really helped me think deeply about promises. A promise is basically an object that represents the result of an asynchronous operation. That result can be your desired value or an error. For example if you are making a fetch request for some posts then the desired result is the array of posts. If something goes wrong on the server then the result is an error telling you what went wrong. Either way you get a result from the promise, a desired value or an error.
To highlight JavaScript syntax, you just write the word JavaScript or js after the opening triple quote:
letmyPromise=getPromise(URL_RETURNING_MULTIPLE_ITEMS);promise.then(result=>{// extracts URL of oneItemletoneItem=JSON.parse(result).results[0].url;returnoneItem;// returns the URL}).then(oneItemURL=>{console.log(oneItemURL);returngetPromise(oneItemURL);// new promise returned}).then(itemData=>{console.log(JSON.parse(itemData));}).catch(error=>{console.log(‘Errorcaught.IntheCatchblock’,error);});
Great article
It really helped me think deeply about promises. A promise is basically an object that represents the result of an asynchronous operation. That result can be your desired value or an error. For example if you are making a fetch request for some posts then the desired result is the array of posts. If something goes wrong on the server then the result is an error telling you what went wrong. Either way you get a result from the promise, a desired value or an error.
Thank you 🙌
To highlight JavaScript syntax, you just write the word JavaScript or js after the opening triple quote:
Thank you so much for that input!
It was really useful. Thank’s!
same here,
Great article
Thanks!
Nice article. Thanks for sharing. You helped me clear more points on promises which helps me a lot in my projects.
Thanks, glad it helped you!
Great job on your first article 🎉. You totally should give observables (and rxjs) a look though.
Will do 🙌 Thanks for the suggestion!