- 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
I'm a longtime Network admin who has finally moved over to coding. Skilled in web development and obsessed with frameworks (Angular, Meteor and Ionic to name a few), I am using my past experience as an instructor to help others learn to use technology.