Here's an example using promises for fetching data from an API:
function fetchData() {
return new Promise((resolve, reject) => {
// Simulating an API call
setTimeout(() => {
const data = { message: "Data fetched successfully!" };
resolve(data);
}, 2000);
});
}