
Modern JS Talk Promise
This article was originally published on bmf-tech.com . ※This article is a reprint from the Innovator Japan Engineers’ Blog . What is a Promise A Promise is... The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. MDN - Promise That's what it is. In summary, a Promise is an object that nicely handles asynchronous operations and their results . Using Promises provides the following main benefits: Reduces nesting Improves readability Allows passing the result of one operation to the next Enables catching exceptions Let's look at some examples of using Promises. Asynchronous Processing Without Promises Here is an example of asynchronous processing using callbacks without Promises. // Example of a higher-order function without Promises const asyncSayHi = ( greet , callback ) => { setTimeout ( function () { callback ( greet ); }, 1000 ); }; asyncSayHi ( ' Hello ' , ( value ) => { console . log ( value ); }); // Output: Hell
Continue reading on Dev.to JavaScript
Opens in a new tab


