Created
November 29, 2019 05:47
-
-
Save prashant1k99/d0ae9ae63a3d01ec3e429a6297e9c6ec to your computer and use it in GitHub Desktop.
Promises in JS
This file contains 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
var promise = new Promise(function(resolve, reject) { | |
throw new Error('Some error has occured') | |
}) | |
promise | |
.then(function(successMessage) { | |
console.log(successMessage); | |
}) | |
.catch(function(errorMessage) { | |
//error handler function is invoked | |
console.log(errorMessage); | |
}); |
This file contains 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
var promise = new Promise(function(resolve, reject) { | |
reject('Promise Rejected') | |
}) | |
promise | |
.then( (successMessage) => { | |
console.log(successMessage); | |
}) | |
.catch((errorMessage) => { | |
console.log(errorMessage); | |
}); |
This file contains 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
var promise = new Promise(function(resolve, reject) { | |
resolve('Geeks For Geeks'); | |
}) | |
promise | |
.then((successMessage) => { | |
//success handler function is invoked | |
console.log(successMessage); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment