Awaiting Promises with async/await in Javascript


Use async/await for cleaner asynchronous code.

Source Code

async function fetchData() {
  try {
    let response = await fetch('https://api.example.com/data');
    let data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments