Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
// Function returns a Promise
async function fetchData(): Promise
{ // In a real scenario, we would actually fetch from an API // This is a mock implementation for demonstration return new Promise((resolve) => { setTimeout(() => { resolve("Response from server"); }, 1000); }); } // Using the async function async function displayData() { try { console.log("Fetching data..."); const data = await fetchData(); // TypeScript knows 'data' is a string console.log("Data length:", data.length); console.log("Data:", data); } catch (error) { console.error('An error occurred:', error); } } // Call the async function displayData();
Console Output:
Fetching data... Data length: 19 Data: Response from server