Basically whenever you have an asynchronous action (i.e., you don’t know how long it will take to finish executing, like a network request for example) there are different ways of telling the browser what you want to do once the action is complete. Callbacks and Promises are two different ways of accomplishing this.
Take, for example, our function
.search. With callbacks, you pass a function as an argument into
search, with the expectation that it will be executed when the asynchronous action is complete.
With Promises, you expect that
.search will kick off the asynchronous action, and then return a “Promise” to you – basically an object with a few methods on it. One of those methods is
.then says – “whatever I write after
.then, run it once the asynchronous action completes.”
But in this case, it looks like whoever designed the
giphy-js-sdk-core package structured it to take in a callback instead.
EDIT: I may have to eat my words – I’m re-reading this documentation and it looks like if you don’t pass in a callback, it should default to a promise??? I’ll dig into it some more