Skip to content

Commit 39453c1

Browse files
committed
text tweaks
1 parent 40b50bf commit 39453c1

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Week4/Closures (class 10).md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ 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 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.
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

24-
> Returning an inner function that accesses arguments and/or variables of its outer function creates (what we call) a **closure**.
24+
> A closure is an inner function that has access to the outer (enclosing) function’s variables and arguments.
2525
2626
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

@@ -55,7 +55,10 @@ console.log(hasanGreeting);
5555

5656
### Recommended further reading
5757

58-
[Eloquent JavaScript - Chapter 3: Functions](http://eloquentjavascript.net/03_functions.html) (Press Ctrl+F in your browser and search for the word 'closure')
58+
- [Eloquent JavaScript - Chapter 3: Functions](http://eloquentjavascript.net/03_functions.html)
59+
(Press Ctrl+F in your browser and search for the word 'closure')
60+
61+
- [Understand JavaScript Closures With Ease](http://javascriptissexy.com/understand-javascript-closures-with-ease/)
5962

6063

6164

0 commit comments

Comments
 (0)