Promises Flashcards
1
Q
What is the Promise signature?
A
var p = new Promise( function (resolve, reject) { // do something possibly asyn // if it works, call resolve() // if not, reject() } );
2
Q
How do you use a promise with then?
A
if p is a Promise: p.then( function(result) { // success! }, function(err) { // fail! } )
3
Q
if getJSON() returns a promise, use async/await to log the response with a function called getAsync()
A
getAsync = async () => console.log( await getJSON() )
4
Q
If p is a promise, use then to log the response when ready.
A
p.then(function(success) {
console.log(success);
}, function(err) {
// error
});