Skip to content

Commit 261467a

Browse files
committed
Callback functions
1 parent 916144a commit 261467a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

12_Asynchronous_Concepts/12.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ const functionTwo = () => {
3737

3838
```
3939

40-
```
40+
#### Callback functions
41+
42+
```js
43+
// Callback functions
44+
45+
const fetchUser = (username, callback) => {
46+
setTimeout(() => {
47+
callback({ username });
48+
}, 2000);
49+
};
4150

51+
fetchUser("Shubham", (user) => {
52+
console.log(`Hello, ${user.username}`); // Hello, Shubham
53+
});
4254
```
4355

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Callback functions
2+
3+
const fetchUser = (username, callback) => {
4+
console.log("Fetching...");
5+
setTimeout(() => {
6+
callback({ username });
7+
}, 2000);
8+
};
9+
10+
fetchUser("Shubham", (user) => {
11+
console.log(`Hello, ${user.username}`);
12+
});

0 commit comments

Comments
 (0)