javascript promise resolve rejectr code example
Example 1: making promises in js
getData()
.then(data => console.log(data))
.catch(error => console.log(error));
Example 2: return new Promise(res => {
// the execution: catch -> then
new Promise((resolve, reject) => {
throw new Error("Whoops!");
}).catch(function(error) {
alert("The error is handled, continue normally");
}).then(() => alert("Next successful handler runs"));