Skip to content

Commit c6723d0

Browse files
professional proofread from Educative.io staff
1 parent 6f62a6a commit c6723d0

21 files changed

+161
-160
lines changed

ebook/01_var_let_const.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ With the introduction of `let` and `const` in **ES6**, we can now better define
66

77
## `Var`
88

9-
Variables declared with the `var` keyword are **function scoped**, which means that if we declare them inside a `for` loop (which is a **block** scope) they will be available even outside of it.
9+
Variables declared with the `var` keyword are **function scoped**, which means that if we declare them inside a `for` loop (which is a **block** scope), they will be available even outside of it.
1010

1111
```JavaScript
1212
for (var i = 0; i < 10; i++) {
@@ -26,7 +26,7 @@ console.log(functionScoped);
2626
// ReferenceError: functionScoped is not defined
2727
```
2828

29-
In the first example the value of the `var` leaked out of the block-scope and could be accessed from outside of it, whereas in the second example `var` was confined inside a function-scope and we could not access it from outside.
29+
In the first example the value of the `var` leaked out of the block-scope and could be accessed from outside of it, whereas in the second example `var` was confined inside a function-scope, and we could not access it from outside.
3030

3131
&nbsp;
3232

@@ -62,13 +62,13 @@ console.log(y);
6262
// expected output: block-scoped
6363
```
6464

65-
As you can see, when we assigned a new value to the variable declared with `let` inside our block-scope, it **did not** change its value in the outer scope. Whereas, when we did the same with the variable declared with var, it leaked outside of the block-scope and also changed it in the outer scope.
65+
As you can see, when we assigned a new value to the variable declared with `let` inside our block scope, it **did not** change its value in the outer scope. Whereas, when we did the same with the variable declared with var, it leaked outside of the block scope and also changed it in the outer scope.
6666

6767
&nbsp;
6868

6969
## `Const`
7070

71-
Similarly to `let`, variables declared with `const` are also **block-scoped**, but they differ in the fact that their value **can't change through re-assignment or can't be re-declared**.
71+
Similarly to `let`, variables declared with `const` are also **block scoped**, but they differ in the fact that their value **can't change through re-assignment and can't be re-declared**.
7272

7373
```JavaScript
7474
const constant = 'I am a constant';
@@ -82,7 +82,7 @@ This **does not** mean that variables declared with `const` are immutable.
8282

8383
&nbsp;
8484

85-
### The content of a `const` is an Object
85+
### The content of a `const` is an object
8686

8787
```JavaScript
8888
const person = {
@@ -95,11 +95,11 @@ console.log(person.age);
9595
// 26
9696
```
9797

98-
In this case we are not reassigning the whole variable but just one of its properties, which is perfectly fine.
98+
In this case we are not reassigning the whole variable but just one of its properties, which works fine fine.
9999

100100
---
101101

102-
>Note: We can still freeze the `const` object, which will not change the contents of the object (but trying to change the values of object `JavaScript` will not throw any error)
102+
>Note: We can still freeze the `const` object, which will not change the contents of the object (but trying to change the values of object `JavaScript` will not throw any error).
103103
104104
```JavaScript
105105
const person = {
@@ -123,7 +123,7 @@ console.log(person.age);
123123

124124
## The temporal dead zone
125125

126-
Now we will have a look at a very important concept which may sound complicated from its name, but I assure you it is not.
126+
Now, we’ll have a look at a very important concept which may sound complicated because of its name, but I assure you it's not.
127127

128128
First let's have a look at a simple example:
129129

@@ -142,7 +142,7 @@ let j = "I am a let";
142142
`var` can be accessed **before** they are defined, but we can't access their **value**.
143143
`let` and `const` can't be accessed **before we define them**.
144144

145-
Despite what you may read on other sources, both `var` and `let`(and `const`) are subject to **hoisting** which means that they are processed before any code is executed and lifted up to the top of their scope (whether it's global or block).
145+
Despite what you may read on other sources, both `var` and `let`(and `const`) are subject to **hoisting**, which means that they are processed before any code is executed and lifted up to the top of their scope (whether it's global or block).
146146

147147
The main differences lie in the fact that `var` can still be accessed before they are defined. This causes the value to be `undefined`. While on the other hand, `let` lets the variables sit in a **temporal dead zone** until they are declared. And this causes an error when accessed before initialization, which makes it easier to debug code rather than having an `undefined` as the result.
148148

@@ -151,7 +151,7 @@ The main differences lie in the fact that `var` can still be accessed before the
151151

152152
## When to use `Var`, `Let` and `Const`
153153

154-
There is no rule stating where to use each of them and people have different opinions. Here I am going to present to you two opinions from popular developers in the `JavaScript` community.
154+
There is no rule stating where to use each of them, and people have different opinions. Here I am going to present to you two opinions from popular developers in the `JavaScript` community.
155155

156156
The first opinion comes from [Mathias Bynes:](https://mathiasbynens.be/notes/es6-const)
157157

ebook/02_arrow_functions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ var greeting = (name) => {
1919
}
2020
```
2121

22-
We can go further, if we only have one parameter we can drop the parenthesis and write:
22+
We can go further if we only have one parameter. We can drop the parentheses and write:
2323

2424
```JavaScript
2525
var greeting = name => {
2626
return `hello ${name}`;
2727
}
2828
```
2929

30-
If we have no parameter at all we need to write empty parenthesis like this:
30+
If we have no parameters at all, we need to write empty parenthesis like this:
3131

3232
```JavaScript
3333
var greeting = () => {
@@ -39,7 +39,7 @@ var greeting = () => {
3939

4040
## Implicitly return
4141

42-
With arrow functions we can skip the explicit `return` and return like this:
42+
With arrow functions, we can skip the explicit `return` and return like this:
4343

4444
```JavaScript
4545
const greeting = name => `hello ${name}`;
@@ -64,7 +64,7 @@ const arrowFunction = (name) => {
6464
}
6565
```
6666

67-
Let's say we want to implicitly return an **object literal**, we would do it like this:
67+
Lets say we want to implicitly return an object literal. We’d do it like this:
6868

6969
```JavaScript
7070
const race = "100m dash";
@@ -78,9 +78,9 @@ console.log(results);
7878
// {name: "Asafa Powell", race: "100m dash", place: 3}]
7979
```
8080

81-
In this example, we are using the `map` function to iterate over the array `runners`. The first argument is the current item in the array and the `i` is the index of it. For each item in the array we are then adding into `results` an Object containing the properties `name`, `race`, and `place`.
81+
In this example, we're using the `map` function to iterate over the array `runners`. The first argument is the current item in the array, and the `i` is the index of it. For each item in the array we are then adding into `results` an Object containing the properties `name`, `race`, and `place`.
8282

83-
To tell `JavaScript` what's inside the curly braces is an **object literal** we want to implicitly return, we need to wrap everything inside parenthesis.
83+
To tell `JavaScript` what's inside the curly braces is an **object literal** we want to implicitly return, so we need to wrap everything inside parentheses. Writing `race` or `race: race` is the same.
8484

8585
Writing `race` or `race: race` is the same.
8686

@@ -157,7 +157,7 @@ box.addEventListener("click", function() {
157157

158158
Here, the second `this` will inherit from its parent, and will be set to the `const` box.
159159

160-
Running the example code you should see our `div` turning red for just half a second.
160+
Running the example code, you should see our `div` turning red for just half a second.
161161

162162
&nbsp;
163163

@@ -205,7 +205,7 @@ const person2 = {
205205
person2.grow();
206206
```
207207

208-
Another difference between Arrow functions and normal functions is the access to the `arguments object`.
208+
Another difference between arrow functions and normal functions is the access to the `arguments object`.
209209
The `arguments object` is an array-like object that we can access from inside functions and contains the values of the arguments passed to that function.
210210

211211
A quick example:
@@ -221,7 +221,7 @@ example(1,2,3);
221221

222222
As you can see we accessed the first argument using an array notation `arguments[0]`.
223223

224-
Similarly to what we saw with the `this` keyword, Arrow functions inherit the value of the `arguments object` from their parent scope.
224+
Similarly to what we saw with the `this` keyword, arrow functions inherit the value of the `arguments object` from their parent scope.
225225

226226
Let's have a look at this example with our previous list of runners:
227227

@@ -240,7 +240,7 @@ This code will return:
240240
ReferenceError: arguments is not defined
241241
```
242242

243-
To access all the arguments passed to the function we can either use the old function notation or the spread syntax(which we will discuss more in Chapter 9)
243+
To access all the arguments passed to the function we can either use the old function notation or the spread syntax (which we will discuss more in Chapter 9)
244244

245245
Remember that `arguments` is just a keyword, it's not a variable name.
246246

ebook/03_default_function_arguments.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ getLocation('Paris','France')
2020
// Europe France Paris
2121
```
2222

23-
As you can see our function takes three arguments, a city, a country and a continent. In the function body we are checking if either country or continent are `undefined` and in that case we are giving them a **default value**.
23+
As you can see, our function takes three arguments: a city, a country and a continent. In the function body we are checking if either country or continent are `undefined` and in that case, we are giving them a **default value**.
2424

2525
When calling `getLocation('Milan')` the second and third parameter (country and continent) are undefined and get replaced by the default values of our functions.
2626

@@ -44,7 +44,7 @@ getLocation(undefined,'Paris','France')
4444
// Europe Paris France
4545
```
4646

47-
If we want to replace any of the first arguments with our default we need to pass them as `undefined`, not really a nice looking solution. Luckily ES6 came to the rescue with default function arguments.
47+
If we want to replace any of the first arguments with our default we need to pass them as `undefined`, which is not the nicest looking solution. Luckily, ES6 came to the rescue with default function arguments.
4848

4949
&nbsp;
5050

@@ -91,7 +91,7 @@ const bill = calculatePrice({ tip: 0.15, total:150 });
9191

9292
We made the argument of our function an Object. When calling the function, we don’t even have to worry about the order of the parameters because they are matched based on their key.
9393

94-
In the example above the default value for *tip* was 0.05 and we overwrote it with 0.15 but we didn't give a value to tax which remained the default 0.1.
94+
In the example above, the default value for *tip* was 0.05, and we overwrote it with 0.15. But we didnt give a value to tax which remained the default 0.1.
9595

9696
Notice this detail:
9797

@@ -103,7 +103,7 @@ Notice this detail:
103103
} = {}
104104
```
105105

106-
If we don't default our argument Object to an empty Object, and we were to try and run `calculatePrice()` we would get:
106+
If we don't default our argument Object to an empty Object, and we were to try and run `calculatePrice()`, we would get:
107107

108108
```JavaScript
109109
Cannot destructure property `total` of 'undefined' or 'null'.

ebook/04_template_literals.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Chapter 4: Template literals
22

3-
Prior to ES6 they were called *template strings*, now we call them *template literals*. Let's have a look at what changed in the way we interpolate strings in ES6.
3+
*Template literals* were called *template strings prior* to ES6.. Lets have a look at what’s changed in the way we interpolate strings in ES6.
44

55
&nbsp;
66

77
## Interpolating strings
88

9-
In ES5 we used to write this, in order to interpolate strings:
9+
We used to write the following in ES5 in order to interpolate strings:
1010

1111
```JavaScript
1212
var name = "Alberto";
@@ -16,7 +16,7 @@ console.log(greeting);
1616
// Hello my name is Alberto
1717
```
1818

19-
In ES6 we can use backticks to make our lives easier.
19+
In ES6m we can use backticks to make our lives easier.
2020

2121
```JavaScript
2222
let name = "Alberto";
@@ -40,7 +40,7 @@ console.log('1 * 10 is ' + ( a * b));
4040

4141
```
4242

43-
In ES6 we can use backticks to reduce our typing:
43+
In ES6 we simply have to wrap everything inside backticks, so backslashes on each line aren’t needed anymore.
4444

4545
```JavaScript
4646
var a = 1;
@@ -100,7 +100,7 @@ console.log(markup);
100100
// </ul>
101101
```
102102

103-
Here we are using the `map` function to loop over each of our `people` and display a `li` tag containing the `name` of the person.
103+
Here, we're using the `map` function to loop over each of our `people` and display a `li` tag containing the `name` of the person.
104104

105105
&nbsp;
106106

@@ -120,7 +120,7 @@ getPrice();
120120
// $20
121121
```
122122

123-
If the condition before the `?` can be converted to `true` then the first value is returned, else it's the value after the `:` that gets returned.
123+
If the condition before the `?` can be converted to `true` then the first value is returned. Otherwise, it's the value after the `:` that gets returned.
124124

125125
```javascript
126126
// create an artist with name and age
@@ -155,7 +155,7 @@ const artist = {
155155

156156
## Pass a function inside a template literal
157157

158-
Similarly to the example above (line 10 of the code), if we want to, we can pass a function inside a template literal.
158+
Similarly to the example above (line 10 of the code), we can pass a function inside a template literal.
159159

160160
```javascript
161161
const groceries = {
@@ -197,16 +197,16 @@ const markup = `
197197
// <div>
198198
```
199199

200-
Inside of the last `p` tag we are calling our function `groceryList` passing it all the `others` groceries as an argument.
201-
Inside of the function we are returning a `p` tag and we are using `map` to loop over each of our items in the grocery list returning an Array of `span` tags containing each grocery. We are then using `.join('\n')` to add a new line after each of those span.
200+
Inside of the last `p` tag, we're calling our function `groceryList` and passing it all the `others` groceries as an argument.
201+
Inside of the function, we're returning a `p` tag and are using `map` to loop over each of our items in the grocery list. This includes returning an array of `span` tags containing each grocery. We're then using `.join('\n')` to add a new line after each of those spans.
202202

203203
&nbsp;
204204

205205
## Tagged template literals
206206

207-
By tagging a function to a template literal we can run the template literal through the function, providing it with everything that's inside of the template.
207+
By tagging a function to a template literal, we can run the template literal through the function, providing it with everything that's inside of the template.
208208

209-
The way it works is very simple: you just take the name of your function and put it in front of the template that you want to run it against.
209+
The way it works is very simple: you take the name of your function and put it in front of the template that you want to run it against.
210210

211211
```javascript
212212
let person = "Alberto";
@@ -227,9 +227,9 @@ console.log(sentence);
227227
```
228228

229229
We captured the value of the variable age and used a ternary operator to decide what to print.
230-
`strings` will take all the strings of our `let` sentence whilst the other parameters will hold the variables.
230+
`strings` will take all the strings of our `let` sentence, while the other parameters will hold the variables.
231231

232-
In our example our string is divided in 3 pieces: `${person}`, `is a` and `${age}`.
232+
In our example the string is divided into 3 pieces: `${person}`, `is a` and `${age}`.
233233
We use array notation to access the string in the middle like this:
234234

235235
```javascript

ebook/05_additional_string_methods.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ str.toLowerCase()
4242
// Output: "i ate an apple"
4343
```
4444

45-
There are many more methods; these were just a few as a reminder. Check the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#) for a more in-depth description on the above methods.
45+
There are many more methods- these were just a few as a reminder. Check the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#) for a more in-depth description of the above methods.
4646

4747
&nbsp;
4848

@@ -85,7 +85,7 @@ code.startsWith("DEF",3);
8585

8686
### `endsWith()`
8787

88-
Similarly to `startsWith()` this new method will check if the string ends with the value we pass in:
88+
Similarly to `startsWith()`, this new method will check if the string ends with the value we pass in:
8989

9090
```javascript
9191
const code = "ABCDEF";

ebook/06_destructuring.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const person = {
3333
const { first, last } = person;
3434
```
3535

36-
Since our `const` variable, `person`, have the same name as the properties we want to grab, we don't have to specify `person.first` and `person.last` anymore.
36+
Since our `const` variable- `person`- has the same name as the properties we want to grab, we don't have to specify `person.first` and `person.last` anymore.
3737

3838
The same applies even when we have nested data, such as what we could get from an API.
3939

@@ -52,7 +52,7 @@ const person = {
5252
const { facebook } = person.links.social;
5353
```
5454

55-
We are not limited to name our variable the same as the property of the object. We can also rename as the following:
55+
We're not limited to name our variables the same as the property of the object. We can also rename as the following:
5656

5757
```javascript
5858
const { facebook:fb } = person.links.social;
@@ -61,7 +61,7 @@ console.log(fb); // https://www.facebook.com/alberto.montalesi
6161
console.log(facebook); //ReferenceError: facebook is not defined
6262
```
6363

64-
We are using the syntax `const { facebook:fb }` to specify that we want to target the property `facebook` of the Object `person.links.social` and we want the `const` variable to be called `fb`.
64+
We're using the syntax `const { facebook:fb }` to specify that we want to target the property `facebook` of the object `person.links.social`, and that we want the `const` variable to be called `fb`.
6565
That is why when we try to log `facebook` we get an error.
6666

6767
We can also pass in **default values** like this:
@@ -75,7 +75,7 @@ const { facebook:fb = "https://www.facebook.com"} = person.links.social;
7575

7676
## Destructuring Arrays
7777

78-
The first difference we notice when **destructuring arrays** is that we are going to use `[]` and not `{}`.
78+
The first difference we notice when **destructuring arrays** is that we're going to use `[]` and not `{}`.
7979

8080
```javascript
8181
const person = ["Alberto","Montalesi",25];
@@ -93,7 +93,7 @@ console.log(name,surname);
9393
// Alberto Montalesi
9494
```
9595

96-
Let's say we want to grab all the other values remaining, we can use the **rest operator**:
96+
Let's say we want to grab all the other values remaining. We can use the **rest operator** for that:
9797

9898
```javascript
9999
const person = ["Alberto", "Montalesi", "pizza", "ice cream", "cheese cake"];
@@ -103,7 +103,7 @@ console.log(food);
103103
// Array [ "pizza", "ice cream", "cheese cake" ]
104104
```
105105

106-
In the example above the first two values of the array were bound to `name` and `surname` while the rest (that's why it's called the **rest operator**) get assigned to `food`
106+
In the example above, the first two values of the array were bound to `name` and `surname`, while the rest (that's why it's called the **rest operator**) get assigned to `food`
107107

108108
The `...` is the syntax for the **rest operator**.
109109

0 commit comments

Comments
 (0)