Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 442b8d4

Browse files
Async and Await
1 parent f89638f commit 442b8d4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

‎12_Asynchronous_Concepts/script2.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ const fetchPhotoDetails = (photo) => {
2626
});
2727
};
2828

29-
fetchUser("Shubham")
30-
.then((user) => fetchUserPhotos(user.username))
31-
.then((photos) => fetchPhotoDetails(photos[0]))
32-
.then((details) => console.log(`Your photo details are ${details}`));
29+
// This was one way of calling the function
30+
// fetchUser("Shubham")
31+
// .then((user) => fetchUserPhotos(user.username))
32+
// .then((photos) => fetchPhotoDetails(photos[0]))
33+
// .then((details) => console.log(`Your photo details are ${details}`));
34+
35+
// The second way is using Async ==> Await
36+
37+
const displayData = async () => {
38+
const user = await fetchUser("Shubham");
39+
const photos = await fetchUserPhotos(user.username);
40+
const details = await fetchPhotoDetails(photos[0]);
41+
42+
console.log(details);
43+
};
44+
45+
displayData();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /