js then
doSomething()
.then(function(result) {
return doSomethingElse(result);
})
.catch(failureCallback);
js then
doSomething()
.then(function(result) {
return doSomethingElse(result);
})
.catch(failureCallback);
promise catch
//create a Promise
var p1 = new Promise(function(resolve, reject) {
resolve("Success");
});
//Execute the body of the promise which call resolve
//So it execute then, inside then there's a throw
//that get capture by catch
p1.then(function(value) {
console.log(value); // "Success!"
throw "oh, no!";
}).catch(function(e) {
console.log(e); // "oh, no!"
});
then js
new Promise( (res, rej) => {
setTimeout(() => res(1), 1000);
}).then( (res) => {
console.log(res); // 1
return res*2
}).then( (res) => {
console.log(res); // 2
});
.then javascript
const promise2 = doSomething().then(successCallback, failureCallback);
js return a promise
function myAsyncFunction(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us