Are you looking to learn more about JavaScript Await? This tutorial is designed for beginners and will provide an introduction to the concept of asynchronous programming in JavaScript. We'll go over the basics of JavaScript Await, including what it is, why you should use it, and how to use it in your code.
async function getData() {
const data = await fetch('https://example.com/data');
return data;
}
async function main() {
const data = await getData();
console.log(data);
}
main();
async function getData1() {
const data1 = await fetch('https://example.com/data1');
return data1;
}
async function getData2() {
const data2 = await fetch('https://example.com/data2');
return data2;
}
async function main() {
const data1 = await getData1();
const data2 = await getData2();
console.log(data1, data2);
}
main();
async function getData(url) {
const data = await fetch(url);
return data;
}
async function main() {
const urls = [
'https://example.com/data1',
'https://example.com/data2',
'https://example.com/data3',
];
const data = [];
for (const url of urls) {
const res = await getData(url);
data.push(res);
}
console.log(data);
}
main();
async function getData() {
const data = await fetch('https://example.com/data')
.catch((err) => {
console.error(err);
});
return data;
}
async function main() {
const data = await getData();
console.log(data);
}
main();