SHARE
TWEET

Untitled

a guest Jul 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const sampleCallBack = (callback) => {
  2.     setTimeout(() => {
  3.         callback('This is an error', undefined)
  4.     }, 2000)
  5. }
  6.  
  7. sampleCallBack((error, result) => {
  8.     if (error) {
  9.         return console.log(error)
  10.     }
  11.     console.log(result)
  12. })
  13.  
  14. const samplePromise = new Promise((resolve, reject) => {
  15.     setTimeout(() => {
  16.         resolve('Hi there')
  17.         //reject('Hi there')
  18.     }, 2000);
  19. })
  20.  
  21. samplePromise.then((result) => {
  22.     console.log('success', result)
  23. }).catch((error) => {
  24.     console.log('error', error)
  25. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top