Last active
November 19, 2019 14:23
-
-
Save craicoverflow/903018b7466504d72cd180f9acffca67 to your computer and use it in GitHub Desktop.
JavaScript Async Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isSuccess(success) { | |
return new Promise(function (resolve, reject) { | |
if (success === true) { | |
resolve('Success'); | |
} else { | |
reject('Error'); | |
} | |
}); | |
} | |
console.log(0); | |
let promise1 = isSuccess(true); | |
promise1.then(function (success) { | |
console.log(success); | |
}).catch(function (err) { | |
console.log(err); | |
}); | |
const promise2 = isSuccess(false); | |
promise2.then(function (success) { | |
console.log(success); | |
}).catch(err => { | |
console.log(err); | |
}) | |
console.log(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment