Created
November 8, 2022 19:29
-
-
Save ahamilton9/ca921405ed27294de426a09d9263f912 to your computer and use it in GitHub Desktop.
On Promises
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
new Promise( ( resolve, reject ) => { | |
resolve('result'); | |
}) | |
.then(() => {console.log('resolved');}, () => {console.log('rejected');}) | |
.catch(() => {console.log('error thrown');}); | |
// resolved | |
new Promise( ( resolve, reject ) => { | |
reject('error'); | |
}) | |
.then(() => {console.log('resolved');}, () => {console.log('rejected');}) | |
.catch(() => {console.log('error thrown');}); | |
// rejected | |
new Promise( ( resolve, reject ) => { | |
throw 'error'; | |
}) | |
.then(() => {console.log('resolved');}, () => {console.log('rejected');}) | |
.catch(() => {console.log('error thrown');}); | |
// rejected | |
new Promise( ( resolve, reject ) => { | |
reject('error'); | |
}) | |
.catch(() => {console.log('error thrown');}); | |
// error thrown | |
new Promise( ( resolve, reject ) => { | |
throw 'error'; | |
}) | |
.catch(() => {console.log('error thrown');}); | |
// error thrown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment