I am currently learning how to use ES8 fetch, async and expect that I have this code that works:
const url = "https://api.icndb.com/jokes/random";
async function tellJoke() {
let data = await (await fetch(url)).json();
return data.value.joke;
}
tellJoke().then(data => console.log(data));
Console:
"Chuck Norris can dereference NULL."
but I found a snippet using the arrow function, the problem is that I don’t know how to return the value, as I do in my current example.
SNIPPET:
const fetchAsync = async () =>
await (await fetch(url)).json()
If this is not best practice, let me know, any further reading is also welcome.
source
share