Created
September 26, 2020 08:07
-
-
Save arkumish/52aae5420e147f1f36d264fd1b0ad96f to your computer and use it in GitHub Desktop.
Promises in JS
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
// In real life, you make promise for doing something. Based upon ur success and failure of ur promise, u have to don certain task. | |
// same way, Promises work in JS, check following example | |
let p = new Promise((resolve,reject)=>{ | |
let a=true; | |
if(a){resolve("success")} | |
else{reject("failed")} | |
}) | |
p.then((message)=>{ | |
//this is success case | |
console.log(message) //output : success | |
}).catch((message)=>{ | |
//this is fail case | |
console.log(message) //output : failed | |
}) | |
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 handleMyinfo{ | |
return new Promis((resolve,reject)=>{ | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment