Syntax for writing asynchronous code in a synchronous-looking style.
Syntax
async function fn() { const v = await promise; }Example
Enter values below to update the example in real time.
async→function→fetchData→url→string→try→const→response→await→data→return→catch→error→console→async function fetchData(url: string) {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch (error) {
console.error(error);
}
}