You can handle asynchronous code using callbacks, Promises, or async/await. The async/await
syntax, introduced in ES2017, allows you to write asynchronous code that looks synchronous. Example:
const fetchData = async () => {
try {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error fetching data:', error);
}
};
fetchData();