What are Promises?

  • Similar to callback functions…however they are MUCH cleaner. If you were to use callback functions for every condition, you’d be in callback hell.

Use Cases:

  • Tell code what to do when an action succeeds (resolve)
  • Tell code what to do when an action fails (reject)
  • Chaining | A promise chain will add a .then statement allowing for cleaner code

Syntax of creating a promise…

Traditional callback functions may look like this…

But a promise chain can look like this…

Learn more about promises on the MDN Webiste: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises