javascript async await json code example
Example 1: javascript async fetch file html
async function () {
element.innerHTML = await (await fetch('./filetofetch.html')).text();
}
Example 2: async await
async function f() {
try {
let response = await fetch('/no-user-here');
let user = await response.json();
} catch(err) {
// catches errors both in fetch and response.json
alert(err);
}
}
f();