Skip to content

Instantly share code, notes, and snippets.

@bhuizi
Last active January 7, 2018 04:55
Show Gist options
  • Save bhuizi/e41ca12cb5cf19a56c278ec7b716dc70 to your computer and use it in GitHub Desktop.
Save bhuizi/e41ca12cb5cf19a56c278ec7b716dc70 to your computer and use it in GitHub Desktop.
promise example
const other = new Promise((resolve, reject) => {
let values = [1,2, 3,4, 5];
let sum = values.reduce((acc, next) => {
return acc + next;
}, 0)
resolve(sum);
reject('something went wrong');
});
let fullName = (first, last) => {
return new Promise((resolve, reject) => {
let fullName = `fullname is ${first} ${last}`;
resolve(fullName);
reject('ooops');
})
}
let joey_smith = fullName('joey', 'smith');
joey_smith.then(data => console.log(data)).catch(err => err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment