From f6f0511100cc1092e70dcfde8f65d23a557e8edf Mon Sep 17 00:00:00 2001 From: Mitch Keenan Date: Tue, 7 Nov 2017 11:36:32 -0400 Subject: [PATCH] Fixed inline code formatting in Closure Section --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 0aa6b4f..225bdfc 100644 --- a/readme.md +++ b/readme.md @@ -156,9 +156,9 @@ const addTo = x => y => x + y var addToFive = addTo(5) addToFive(3) // returns 8 ``` -The function ```addTo()``` returns a function(internally called ```add()```), lets store it in a variable called ```addToFive``` with a curried call having parameter 5. +The function `addTo()` returns a function(internally called `add()`), lets store it in a variable called `addToFive` with a curried call having parameter 5. -Ideally, when the function ```addTo``` finishes execution, its scope, with local variables add, x, y should not be accessible. But, it returns 8 on calling ```addToFive()```. This means that the state of the function ```addTo``` is saved even after the block of code has finished executing, otherwise there is no way of knowing that ```addTo``` was called as ```addTo(5)``` and the value of x was set to 5. +Ideally, when the function `addTo` finishes execution, its scope, with local variables add, x, y should not be accessible. But, it returns 8 on calling `addToFive()`. This means that the state of the function `addTo` is saved even after the block of code has finished executing, otherwise there is no way of knowing that `addTo` was called as `addTo(5)` and the value of x was set to 5. Lexical scoping is the reason why it is able to find the values of x and add - the private variables of the parent which has finished executing. This value is called a Closure.