let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("Resolved"), 1000);
});
promise.then(result => console.log(result)); // Output: Resolved
async function fetchData() {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
return data;
}
async function getData() {
try {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
return data;
} catch (error) {
console.error("Error:", error);
}
}
async function fetchData() {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
return data;
}
async function processData() {
let result1 = await fetch('https://api.example.com/data1');
let result2 = await fetch('https://api.example.com/data2');
return [result1, result2];
}
async function fetchData() {
try {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
return data;
} catch (error) {
console.error("Error:", error);
}
}
async function doSomething() {
let result = await someAsyncFunction();
return result;
}