Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Created October 25, 2019 08:15
Show Gist options
  • Select an option

  • Save anushshukla/da36b8aff3e10fe3936da0d8cdbe2417 to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/da36b8aff3e10fe3936da0d8cdbe2417 to your computer and use it in GitHub Desktop.
Promise and callback example
var promise = canReject => new Promise((resolve, reject) => canReject ? reject('bye') : resolve('hi'))
const thenCallback = message => console.log(message);
const catchCallback = message => console.log(message);
promise()
.then(thenCallback)
.catch(catchCallback)
promise(true)
.then(thenCallback)
.catch(catchCallback)
var greet = callback => typeof callback === 'function' && callback('hi')
var callback = prefix => prefix + ' Jai';
var greetJai = greet(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment