Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  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. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement