Skip to content

Commit fda8472

Browse files
committed
text tweaks
1 parent 62276f7 commit fda8472

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎Week4/Closures (class 10).md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ console.log(timirGreeting);
1717

1818
The `greetPerson` function (the "outer" function) contains another function inside its function body, called `innerFunction`. This inner function has access to the `name` argument of `greetPerson`, as well as its own `greeting` argument.
1919

20-
When we call `greetPerson('Timir')`, the `greetPerson` function sets its `name` argument to the string `'Timir'` and then returns its inner function. This inner function **retains access to the `name` argument** and its value `'Timir'`, even after `greetPerson` exits. Note that `greetPerson` doesn't call its inner function; it just returns it.
20+
When we later call `greetPerson('Timir')`, the `greetPerson` function sets its `name` argument to the string `'Timir'` and returns its inner function. This inner function **retains access to the `name` argument** and its value `'Timir'`, even after `greetPerson` exits. Note that `greetPerson` doesn't call its inner function; it just returns it.
2121

2222
The returned the inner function is subsequently assigned to the variable `greetTimir`.
2323

2424
> Returning an inner function that accesses arguments and/or variables of its outer function creates (what we call) a **closure**.
2525
26-
With `greetTimir('Good morning')` we are now calling effectively calling the inner function, and passing it the string `'Good morning'`. Because the inner function still has acces to `name` it can produce the output printed by `console.log`:
26+
With `greetTimir('Good morning')` we are effectively calling the inner function, passing it the string `'Good morning'`. Because the inner function still has acces to `name` it can produce the output as printed by the `console.log`:
2727

2828
```
2929
Good morning, Timir
3030
```
3131

32-
Alternatively, we could obtain the same result by scrapping all lines except the last two and replace them with the code below. We wouldn't be able to tell the difference from just looking at the output produced.
32+
Alternatively, we could have obtained the same result by scrapping all lines except the last two and replace them with the code below. We wouldn't be able to tell the difference from just looking at the output produced.
3333

3434
```js
3535
function greetTimir(greeting) {
@@ -41,7 +41,7 @@ const timirGreeting = greetTimir('Good morning');
4141
console.log(timirGreeting);
4242
```
4343

44-
However, with that alternative `greetTimir` function we can only greet Timir. In contrast, with the `greetPerson` function we can easily produce functions to greet any person we like (or don't like :wink:), e.g.:
44+
However, with that alternative `greetTimir` function we can only greet Timir. In contrast, with `greetPerson` we can easily produce functions to greet any person we like (or don't like :wink:), e.g.:
4545

4646
```js
4747
const greetMaartje = greetPerson('Maartje');

0 commit comments

Comments
 (0)