Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 27, 2019 23:46
Show Gist options
  • Save ilearnjavascript/13bc1c87fa0cee1f195a042c997c37c5 to your computer and use it in GitHub Desktop.
Save ilearnjavascript/13bc1c87fa0cee1f195a042c997c37c5 to your computer and use it in GitHub Desktop.
es8 - async await - 1.js
async function getJoke() {
let url = 'https://api.icndb.com/jokes/random';
let result = await (await fetch(url)).json();
return result;
}
async function initApiCall() {
try {
let data = await getJoke();
console.log(data.value.joke)
}
catch (err) {
console.error(`ERROR(${err.code}): ${err.message}`);
}
}
initApiCall();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment