JSFiddle - React, Tailwind, and code Playground
by parksd
JavaScript
// 비동기 함수: fetch 사용
async function fetchData(id) {
console.log(`Fetching data for ID ${id}`);
const response = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
const data = await response.json();
console.log(`Fetched data for ID ${id}:`, data);
}
// 비동기 함수 10개 호출 (await 사용)
async function fetchWithAwait() {
for (let i = 1; i <= 10; i++) {
// await fetchData(i); // await 사용
fetchData(i); // await 미사용
}
}
fetchWithAwait(); // 주석을 풀면 await 미사용