javascript
Published on January 26, 2024By DeveloperBreeze
// Asynchronous function to fetch data from an API
async function fetchData() {
// Fetch data from the specified URL
const response = await fetch('https://api.example.com/data');
// Parse the JSON data from the response
const data = await response.json();
// Return the parsed data
return data;
}
// Call the asynchronous function and handle the returned Promise
fetchData().then((data) => {
// Log the retrieved data to the console
console.log(data);
});
Comments
Please log in to leave a comment.