-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.js
More file actions
36 lines (29 loc) · 794 Bytes
/
Copy pathasync.js
File metadata and controls
36 lines (29 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function fetchData(callback) {
setTimeout(() => {
callback("Data received");
}, 1000);
}
function fetchDataPromise() {
return new Promise((resolve) => {
setTimeout(() => {
resolve("Promise resolved");
}, 1000);
});
}
async function getData() {
let data = await fetchDataPromise();
return data;
}
let output = "Starting async operations...\n";
fetchData((data) => {
output += `Callback: ${data}\n`;
document.getElementById('output').textContent = output;
});
fetchDataPromise().then(data => {
output += `Promise: ${data}\n`;
document.getElementById('output').textContent = output;
});
getData().then(data => {
output += `Async/Await: ${data}`;
document.getElementById('output').textContent = output;
});