Write a JS to demonstrate the use of Async/Await.
Mon Apr 07 2025 15:54:53 GMT+0000 (Coordinated Universal Time)
Saved by
@p9876543
// Simulate a function that returns a promise
function fetchStudentData(id) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ id, name: "John Doe", gpa: 3.7 });
}, 2000);
});
}
// Async function using await
async function displayStudentInfo() {
console.log("⏳ Fetching student data...");
const student = await fetchStudentData(101);
console.log("📄 Student Info:", student);
}
displayStudentInfo();
content_copyCOPY
Comments