Lessons: 2Length: 9 minutes

Next lesson playing in 5 seconds

Cancel
  • 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:

myPromise.then(function(result){
    console.log('Promise resolved: ' + result);
})
.catch(function(reason){
    console.log('Rejected because: ' + reason);
});

Related Links

1.Using JavaScript Promises
2 lessons, 09:07

1.1
Introduction
00:38

1.2
Using JavaScript Promises
08:29