Now, let's say we move our json-getting functionality into a getJson()
function. That function has to be asynchronous, because it's using fetch()
. Which means we need to declare it as async function getJson()
. Which means it will automatically return a Promise
object, so that when we call that function, we need to await
it, assuming we want to do something with the data it returns, which means our calling function needs to be an async
function as well.
I admit it took me a beat or two to wrap my head around this stuff, again, coming out of promise chains and XMLHttpRequest
objects and all that jazz. And maybe I still don't fully understand it but the more I play with it the better a handle on it I think I get and the closer I come to feeling like it's second nature, like, you know, obviously this is how it should be done.