Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
here's how to create promise-based functions
// say take a number and return its double
// resolve : the success call . which goes in the first then
// reject : the error call, which goes in .catch
function double(number){
return new Promise((resolve, reject) => {
if(typeof number == 'number'){
resolve(number * 2)
} else reject("the argument should a Number")
// outputs 8
double(4).then(d => console.log(d))
.catch(err => console.log(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.