Skip to content

Commit 583555e

Browse files
authored
feat(curriculum): add interactive examples to async/await lesson (freeCodeCamp#64145)
1 parent 4f82faf commit 583555e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

curriculum/challenges/english/blocks/lecture-understanding-asynchronous-programming/673407d56c3dce67fa97969b.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ challengeType: 19
55
dashedName: what-is-async-await-and-how-does-it-work
66
---
77

8-
# --description--
8+
# --interactive--
99

1010
In the previous lessons, you learned about asynchronous programming which allows other code to run while we wait for some time-consuming tasks to complete, like fetching data from a server, reading data from a file, and so on.
1111

1212
`async`/`await`, built on top of promises, makes writing and reading asynchronous code easier. When you put the `async` keyword before a function, it means that function will always return a `Promise`. Only inside an `async` function, you can use the `await` keyword, which allows you to wait for a `Promise` to resolve before moving on to the next line of code. Here's an example to illustrate how `async`/`await` works:
1313

14+
:::interactive_editor
15+
1416
```js
1517
async function delayedGreeting(name) {
1618
console.log("A Messenger entered the chat...");
@@ -22,6 +24,8 @@ delayedGreeting("Alice");
2224
console.log("First Printed Message!");
2325
```
2426

27+
:::
28+
2529
In this code, we define an `async` function called `delayedGreeting`. Inside this function, we use `await` to pause the execution for 2 seconds. After the delay, it prints a greeting.
2630

2731
When we call this function, you'll see `First Printed Message!` appear before the greeting. This is because the function is asynchronous - it doesn't block the rest of the code from running.

0 commit comments

Comments
 (0)