From 81ea9f8d698636b87ca8aee1acc99d57432ace69 Mon Sep 17 00:00:00 2001 From: Mohammad Karimi Date: Sat, 21 Sep 2024 22:04:30 +0330 Subject: [PATCH] Question-44 more accurate explanation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b203a060..9254f110 100644 --- a/README.md +++ b/README.md @@ -1363,11 +1363,11 @@ console.log(gen.next().value); #### Answer: C -Regular functions cannot be stopped mid-way after invocation. However, a generator function can be "stopped" midway, and later continue from where it stopped. Every time a generator function encounters a `yield` keyword, the function yields the value specified after it. Note that the generator function in that case doesn’t _return_ the value, it _yields_ the value. +Regular functions cannot be paused mid-way after invocation. However, a generator function can be "paused" midway, and later continue from where it paused. Every time a generator function encounters a `yield` keyword, the function yields the value specified after it. Note that the generator function in that case doesn’t _return_ the value, it _yields_ the value. First, we initialize the generator function with `i` equal to `10`. We invoke the generator function using the `next()` method. The first time we invoke the generator function, `i` is equal to `10`. It encounters the first `yield` keyword: it yields the value of `i`. The generator is now "paused", and `10` gets logged. -Then, we invoke the function again with the `next()` method. It starts to continue where it stopped previously, still with `i` equal to `10`. Now, it encounters the next `yield` keyword, and yields `i * 2`. `i` is equal to `10`, so it returns `10 * 2`, which is `20`. This results in `10, 20`. +Then, we invoke the function again with the `next()` method. It starts to continue where it paused previously, still with `i` equal to `10`. Now, it encounters the next `yield` keyword, and yields `i * 2`. `i` is equal to `10`, so it returns `10 * 2`, which is `20`. This results in `10, 20`.