Last active
July 26, 2024 21:00
-
-
Save franckweb/a981abe204be0ebaca348bf68b1cf71e to your computer and use it in GitHub Desktop.
Javascript Promise
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
const myMethod = function () { | |
const promise = new Promise(function (resolve, reject) { | |
const result = null; | |
const y = "geeksforgeeks"; | |
if (result !== null) { | |
resolve(result); | |
} else { | |
reject("Error"); | |
} | |
}); | |
return promise; | |
}; | |
async function demo() { | |
try { | |
let response = await myMethod(); | |
} catch (error) { | |
} | |
} | |
demo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment