ES6 Promise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

ES6 Promise

This code deserves a better detailed explanation, step by step. I have never used this kind of thing before and I wonder in what cases it can be useful. say it's more readable .. heuuu lol. Maybe with the braces in colone, it's a little more readable. _________________________________________________________________________ function asyncFunc(work) { return new Promise(function(resolve, reject) { if (work === "") reject(Error("Nothing")); setTimeout(function() { resolve(work); }, 1000); }); } asyncFunc("Work 1") // Task 1 ***************** >Step 1 .then(function(result) // { console.log(result); return asyncFunc("Work 2"); // Task 2 }, function(error) { console.log(error); }) .then(function(result) { console.log(result); }, function(error) { console.log(error); }); console.log("End"); _______________________________________________________________________ Question: promise is natif object ? Anyway, I hope I never need it

15th Jun 2020, 12:43 PM
Alain Mazy
Alain Mazy - avatar
2 Answers
+ 1
Here is my video tutorial series about JavaScript Asynchronous Programming https://www.youtube.com/playlist?list=PLkqwj9vc20pX36wThr2A6DZx4MVcJvnhe Explaining Promise and then proceed to async await and fetch, and at last web scraping. These were recorded before I had bought a nice microphone, so please tolerate the low sound volume.
15th Jun 2020, 1:00 PM
Gordon
Gordon - avatar
0
Thanks. ;)
18th Jul 2020, 12:51 PM
Alain Mazy
Alain Mazy - avatar