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()
 } );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you use a promise with then?

A
if p is a Promise:
p.then( function(result) {
    // success!
}, function(err) {
    // fail!
} )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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() )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly