• Overview
  • Transcript

1.2 Using JavaScript Promises

In this lesson we will use promises to control the styling of a page when it loads. First we will use just one promise. After that, we will chain some promises together.

Code Snippet

Here is an example of creating a promise:

var myPromise = new Promise(function(resolve,reject){
    setTimeout(function() {
        resolve("Timeout elapsed");
    }, 10000);

We can then await the resolution of the promise with:

    console.log('Promise resolved: ' + result);
    console.log('Rejected because: ' + reason);

Related Links