can we use promise into promise in javascript code example
Example 1: javascript return promise
function doSomething() {
return new Promise((resolve, reject) => {
console.log("It is done.");
// Succeed half of the time.
if (Math.random() > .5) {
resolve("SUCCESS")
} else {
reject("FAILURE")
}
})
}
const promise = doSomething();
promise.then(successCallback, failureCallback);
Example 2: making promises in js
getData()
.then(data => console.log(data))
.catch(error => console.log(error));