O'Reilly logo

JavaScript by Example by Dani Akash S

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What is a Promise?

You'll probably be wondering by now what it is that I'm calling a Promise? Well, a Promise, as it sounds, is a Promise made by JavaScript that the asynchronous function will complete execution at some point.

In the previous chapter, we came across an asynchronous event: reading the contents of a file using FileReader. This is how FileReader worked:

  • It starts reading the file. Since reading is an asynchronous event, other JavaScript code will continue execution while reading is still happening.

You might be wondering, what if I need to execute some code only after the event is complete? This is how FileReader handles it:

  • Once the reading is complete, FileReader fires a load event
  • It also has an onload() method that listens ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required