We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Why Promises?

Promises are the cleanest (but not the only) way to handle the common scenario where we need to make requests to a server, which is typically done via an HTTP request. JavaScript's built-in fetch() function (that we'll cover in a later course) returns a promise.

I/O, or “input/output”

Almost every time you use a promise it will be to handle some form of I/O. I/O, or input/output, refers to when our code needs to interact with systems outside of the (relatively) simple world of local variables and functions.

Common examples of I/O include:

  • HTTP requests
  • Reading files from the hard drive
  • Interacting with a Bluetooth device
  • Sending data to a database

Promises help us perform I/O without forcing our entire program to freeze up while we wait for a response.