Async function syntax
📖 Scenario: You want to fetch user data from a server and then show a greeting message. Using asynchronous functions helps you wait for the data without freezing the page.
🎯 Goal: Build a simple async function that waits for user data and then prints a greeting message.
📋 What You'll Learn
Create an async function named
getUser that returns a user object after a delay.Create a variable
userId with the value 1.Use
await inside an async function to get the user data.Print the greeting message using the user's name.
💡 Why This Matters
🌍 Real World
Async functions let web pages get data from servers without freezing or waiting, making apps smooth and fast.
💼 Career
Understanding async functions is key for web developers to handle data fetching, user interactions, and background tasks efficiently.
Progress0 / 4 steps