// 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();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter