I'm having trouble with async/await in JavaScript. I have a function that's supposed to fetch data from an API and then process it, but it seems like the processing is happening before the data is actually fetched. How can I make sure that the processing waits for the data?
Here's my current implementation:
async function fetchData() {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
processData(data); // This seems to run too early
}
Even though I'm using await, the processData() function appears to execute before the data is fully retrieved. What am I missing?