Async and Ajax Flashcards
1
Q
What is a promise?
A
An object that represents a task that will be completed in the future.
It’s similar to getting a ticket at the deli meat counter. The ticket is a promise that you will get help, and stepping up to the counter and being helped is like your callback being invoked.
2
Q
What parameters does a Promise take?
A
The Promise constructor takes a single argument - a callback function with two parameters: resolve and reject.
Resolve fires in event of success.
Reject fires in event of failure.
3
Q
How do you use a Promise?
A
With Promise’s then() method.
Then takes two arguments - a success callback and a failure callback, but you can choose to provide only one or the other.
4
Q
A