Skip to content

Commit abe7814

Browse files
fix typos in post 13-20
1 parent 6407324 commit abe7814

10 files changed

+71
-61
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cSpell.enabled": false,
3+
"spellright.language": "English (American)",
4+
"spellright.documentTypes": [
5+
"markdown",
6+
"latex",
7+
"plaintext"
8+
]
9+
}

ebook/03_default_function_arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It works, but it's not very nice, how to improve it?
3030
With **destructuring** we can write this:
3131

3232
``` javascript
33-
const Bill = calculatePrice({ tip: 0.15, total:150});
33+
const Bill = calculatePrice({ tip: 0.15, total:150 });
3434
```
3535

3636
We don't even have to pass the parameters in the same order as when we declared our function, since we are calling them the same way as the arguments JavaScript will know how to match them.

ebook/13_promises.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ fs.readdir(source, function (err, files) {
4848
})
4949
}
5050
})
51-
5251
```
5352

5453
We try to write our code in a way where executions happens visually from top to bottom, causing excessive nesting on functions and result in what you can see above.
@@ -227,12 +226,12 @@ promise1.then(data => {
227226
console.log(data);
228227
});
229228
// after 500 ms
230-
// my first value
229+
// first value
231230
promise2.then(data => {
232231
console.log(data);
233232
});
234233
// after 1000 ms
235-
// my second value
234+
// second value
236235
```
237236

238237
They will resolve independently from one another but look at what happens when we use `Promise.all().`
@@ -245,10 +244,10 @@ Promise
245244
console.log(promise1data, promise2data);
246245
});
247246
// after 1000 ms
248-
// my first value my second value
247+
// first value second value
249248
```
250249

251-
Our values returned together, after 1000ms (the timeout of the *second* promise) meanin that the first one had to wait the completion of the second one.
250+
Our values returned together, after 1000ms (the timeout of the *second* promise) meaning that the first one had to wait the completion of the second one.
252251

253252
If we were to pass an empty iterable then it will return an already resolved promise.
254253

ebook/14_generators.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chapter 14: Generators
22

3-
## What is a Generator ?
3+
## What is a Generator?
44

55
A generator function is a function that we can start and stop, for an indefinite amount of time, and restart with the possibility of passing additional data at a later point in time.
66

@@ -66,7 +66,7 @@ fruitGenerator.next().value;
6666
```
6767

6868
- Our new generator will loop over the array and print one value at a time every time we call `.next()`.
69-
- if you are only concerned about getting the value then use `.next().value` and it will not print the status of the generator
69+
- if you are only concerned about getting the value, then use `.next().value` and it will not print the status of the generator
7070

7171
 
7272

@@ -120,12 +120,13 @@ As you can see when we called `.throw()` the `generator` returned us the error a
120120

121121
 
122122

123-
124123
## Combining Generators with Promises
125124

126-
As we have previously seen, Promises are very useful for asynchronous programming and by combining them with generators we can have a very powerful tool at our disposal to avoid problems like the *callback hell*.
125+
As we have previously seen, Promises are very useful for asynchronous programming, and by combining them with generators we can have a very powerful tool at our disposal to avoid problems like the *callback hell*.
126+
127+
As we are solely discussing ES6, I won't be talking about async functions as they were introduce in ES8 (ES2017) but know that the way they work is based on what you will see now.
127128

128-
As we are solely discussing ES6, I won't be talking about `async functions` as they were introduce in ES8 (ES2017) but know that the way they work is based on what you will see now.
129+
You can read more about async functions in Chapter 19.
129130

130131
Using a Generator in combination with a Promise will allow us to write asynchronous code that feels like synchronous.
131132

@@ -148,8 +149,9 @@ function* gen() {
148149
const asyncFunc = gen();
149150
asyncFunc.next();
150151
// call the promise and wait for it to resolve
152+
// {value: Promise, done: false}
151153
asyncFunc.next();
152154
// Object { value: "our value is... 2", done: false }
153155
```
154156

155-
The first time we call `.next()` it will call our promise and wait for it to resolve( in our simple example it resolves immediately) and when we call `.next()` again it will utilize the value returned by the promise to do something else(in this case just interpolate a string).
157+
The first time we call `.next()` it will call our promise and wait for it to resolve (in our simple example it resolves immediately) and when we call `.next()` again it will utilize the value returned by the promise to do something else (in this case just interpolate a string).

ebook/15_proxies.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ From MDN:
88
99
 
1010

11-
## How to use a Proxy ?
11+
## How to use a `Proxy` ?
1212

1313
This is how we create a Proxy:
1414

1515
``` js
1616
var x = new Proxy(target,handler)
1717
```
1818

19-
- our `target` can be anything, from an object, to a function, to another Proxy
20-
- a `handler` is an object which will define the behavior of our Proxy when an operation is performed on it
19+
- our `target` can be anything, from an object, to a function, to another `Proxy`
20+
- a `handler` is an object which will define the behavior of our `Proxy` when an operation is performed on it
2121

2222
``` js
2323
// our object
@@ -47,6 +47,6 @@ When we call the `get` method we step inside the normal flow and change the valu
4747

4848
When setting a new value we step in again and log a short message before setting the value.
4949

50-
Proxies can be very useful for example if your object is a phone number.
50+
Proxies can be very useful, for example if your object is a phone number.
5151

5252
You can take the value given by the user and format it to match the standard formatting of your country.

ebook/16_sets_weaksets_maps_weakmaps.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ console.log(family);
2626
// Set [ "Dad", "Mom", "Son" ]
2727
```
2828

29-
As you can see, at the end we tried to add "Dad" again but the `Set` still remained the same because a `Set` can only take **unique values**.
29+
As you can see, at the end we tried to add "Dad" again,but the `Set` still remained the same because a `Set` can only take **unique values**.
3030

31-
Let's continue using the same `Set` and see what methd we can use on it.
31+
Let's continue using the same `Set` and see what method we can use on it.
3232

3333
``` js
3434
family.size;
@@ -95,14 +95,14 @@ console.log(uniqueArray);
9595

9696
// write the same but in a single line
9797
const uniqueArray = Array.from(new Set(myArray));
98-
// // Array [ "dad", "mom", "son", "daughter" ]
98+
// Array [ "dad", "mom", "son", "daughter" ]
9999
```
100100

101101
As you can see the new array only contains the unique values from the original array.
102102

103103
 
104104

105-
## What is a `WeakSet` ?
105+
## What is a `WeakSet`?
106106

107107
A `WeakSet` is similar to a `Set` but it can **only** contain Objects.
108108

@@ -138,9 +138,9 @@ As you can see after a few seconds **dad** was removed and *garbage collected*.
138138

139139
 
140140

141-
## What is a `Map` ?
141+
## What is a `Map`?
142142

143-
A `Map` is similar to a `Set` but they have key and value pairs.
143+
A `Map` is similar to a `Set`, but they have key and value pairs.
144144

145145
```js
146146
const family = new Map();
@@ -167,14 +167,13 @@ for(const [key,val] of family){
167167
// Son 20
168168
```
169169

170-
If you remember, we could iterate over a `Set` only with a `for of` loop while we can iterate over a `Map` with both a `for of` and a `forEach` loop.
171-
170+
If you remember, we could iterate over a `Set` only with a `for of` loop, while we can iterate over a `Map` with both a `for of` and a `forEach` loop.
172171

173172
 
174173

175-
## What is a `WeakMap` ?
174+
## What is a `WeakMap`?
176175

177-
A `WeakMap` is a collection of key/value pairs and similarly to a `WeakSet`, even in a `WeakMap` the keys are *weakly* referenced, which means that when the reference is lost the value will be removed from the `WeakMap` and *garbage collected*.
176+
A `WeakMap` is a collection of key/value pairs and similarly to a `WeakSet`, even in a `WeakMap` the keys are *weakly* referenced, which means that when the reference is lost, the value will be removed from the `WeakMap` and *garbage collected*.
178177

179178
A `WeakMap` is **not** enumerable therefore we cannot loop over it.
180179

ebook/17_ES7_incudes-and-exponential-operator.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Chapter 17: Everything new in ES2016 (ES7)
22

3-
4-
53
ES2016 introduced only two new features :
64

75
- `Array.prototype.includes()`
8-
- the exponential operator
6+
- The exponential operator
97

108
 
119

@@ -21,13 +19,14 @@ array.includes(2);
2119
array.includes(3);
2220
// false
2321
```
22+
2423
 
2524

2625
### Combine `includes()` with `fromIndex`
2726

2827
We can provide `.includes()` with an index where to begin searching for an element. Default is 0, but we can also pass a negative value.
2928

30-
The first value we pass is the element to search and the second one is the index:
29+
The first value we pass in is the element to search and the second one is the index:
3130

3231
``` js
3332
let array = [1,3,5,7,9,11];
@@ -42,9 +41,9 @@ array.includes(11,-3);
4241
// true
4342
```
4443

45-
`array.includes(5,4);` returned `false` because, despite the array actually contains the number 5, it is at the index 2 but we started looking at position 4. That's why we couldn't find it and it returned `false`.
44+
`array.includes(5,4);` returned `false` because, despite the array actually contains the number 5, it is found at the index 2 but we started looking at position 4. That's why we couldn't find it and it returned `false`.
4645

47-
`array.includes(1,-1);` returned `false` because we started looking at the index -1 (which is the last element of the array) and then continued from that point onwards.
46+
`array.includes(1,-1);` returned `false` because we started looking at the index -1 (which is the last element of the array) and then continued from that point onward.
4847

4948
`array.includes(11,-3);` returned `true` because we went back to the index -3 and moved up, finding the value 11 on our path.
5049

ebook/18_ES8_string-padding-object-entries-object-values-and-more.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ES2017 introduced many new cool features, which we are going to see here. I will
44

55
## String padding(`padStart` and `padEnd`)
66

7-
We can now add some padding to our strings, either at the end (`padEnd`) or at the beginning (`padStart`).
7+
We can now add some padding to our strings, either at the end (`padEnd`) or at the beginning (`padStart`) of them.
88

99
```js
1010
"hello".padStart(6);
@@ -13,10 +13,10 @@ We can now add some padding to our strings, either at the end (`padEnd`) or at t
1313
// "hello "
1414
```
1515

16-
We said we want 6 as our padding, but why in both cases we got only 1 space?
17-
It happens because `padStart` and `padEnd` will go and fill the empty spaces. In our example "hello" is 5 letters, and our padding is 6, which leaves only 1 empty space.
16+
We specified that we want 6 as our padding, but why in both cases we got only 1 space?
17+
It happens because `padStart` and `padEnd` will go and fill the **empty spaces**. In our example "hello" is 5 letters, and our padding is 6, which leaves only 1 empty space.
1818

19-
Look at this example
19+
Look at this example:
2020

2121
```js
2222
"hi".padStart(10);
@@ -36,7 +36,8 @@ We can use `padStart` if we want to right align something.
3636
```js
3737
const strings = ["short", "medium length", "very long string"];
3838

39-
const longestString = strings.sort(str => str.length).map(str => str.length)[0];
39+
const longestString = strings.sort(str => str.length)
40+
.map(str => str.length)[0];
4041

4142
strings.forEach(str => console.log(str.padStart(longestString)));
4243

@@ -80,7 +81,7 @@ In previous versions of JavaScript we would have accessed the values inside the
8081

8182
```js
8283
Object.keys(family);
83-
// (3) ["father", "mother", "son"]
84+
// ["father", "mother", "son"]
8485
family.father;
8586
"Jonathan Kent"
8687
```
@@ -91,12 +92,12 @@ We now have two more ways of accessing our objects:
9192

9293
```js
9394
Object.values(family);
94-
// (3) ["Jonathan Kent", "Martha Kent", "Clark Kent"]
95+
// ["Jonathan Kent", "Martha Kent", "Clark Kent"]
9596

9697
Object.entries(family);
97-
// (2) ["father", "Jonathan Kent"]
98-
// (2) ["mother", "Martha Kent"]
99-
// (2) ["son", "Clark Kent"]
98+
// ["father", "Jonathan Kent"]
99+
// ["mother", "Martha Kent"]
100+
// ["son", "Clark Kent"]
100101
```
101102

102103
`Object.values()` returns an array of all the values whilst `Object.entries()` returns an array of arrays containing both keys and values.
@@ -145,7 +146,7 @@ const object = {
145146
```
146147

147148
Notice how I wrote a comma at the end of the second property.
148-
It will not throw any error if you don't put it but it's a better practice to follow as it will make the life easier to your colleague or team members.
149+
It will not throw any error if you don't put it, but it's a better practice to follow as it will make the life easier to your colleague or team members.
149150

150151
```js
151152
// I write
@@ -160,7 +161,7 @@ const object = {
160161
prop2: "propop"
161162
prop3: "propopop"
162163
}
163-
// suddenly he gets an error because he did not notice that I forgot to leave a comma at the end of the last parameter.
164+
// suddenly, he gets an error because he did not notice that I forgot to leave a comma at the end of the last parameter.
164165
```
165166

166167

ebook/19_ES8_async-and-await.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ fetch('api.github.com/user/AlbertoMontalesi').then( res => {
1414
// return the data in json format
1515
return res.json();
1616
}).then(res => {
17-
// if everything went well, log the data
17+
// if everything went well, print the data
1818
console.log(res);
1919
}).catch( err => {
20-
// or log the error
20+
// or print the error
2121
console.log(err);
2222
})
2323
```
2424

25-
This is a very simple promise to fetch a user from github and print it to the console.
25+
This is a very simple promise to fetch a user from GitHub and print it to the console.
2626

2727
Let's see a different example:
2828

@@ -61,7 +61,7 @@ walk(1000).then(res => {
6161
// you walked for 700ms
6262
// you walked for 800ms
6363
// uncaught exception: the value is too small
64-
```
64+
```
6565

6666
Let's see how we can rewrite this `Promise` with the new async/await syntax.
6767

@@ -81,7 +81,7 @@ function walk(amount) {
8181

8282
// create an async function
8383
async function go() {
84-
// use the keyword await to wait for the response
84+
// use the keyword `await` to wait for the response
8585
const res = await walk(500);
8686
console.log(res);
8787
const res2 = await walk(900);
@@ -110,13 +110,13 @@ Let's break down what we just did:
110110
- to create an async function we need to put the `async` keyword in front of it
111111
- the keyword will tell JavaScript to always return a promise
112112
- if we specify to `return <non-promise>` it will return a value wrapped inside a promise
113-
- the `await` keyword only works inside an `async` function.
113+
- the `await` keyword **only** works inside an `async` function.
114114
- as the name implies, `await` will tell JavaScript to wait until the promise returns its result
115115

116116
Let's see what happens if we try to use `await` outside an `async` function
117117

118118
```js
119-
// use async inside a normal function
119+
// use await inside a normal function
120120
function func() {
121121
let promise = Promise.resolve(1);
122122
let result = await promise;
@@ -125,13 +125,13 @@ func();
125125
// SyntaxError: await is only valid in async functions and async generators
126126

127127

128-
// use async in the top-level code
128+
// use await in the top-level code
129129
let response = Promise.resolve("hi");
130130
let result = await response;
131131
// SyntaxError: await is only valid in async functions and async generators
132132
```
133133

134-
> *Remember*: you can only use `await` inside an `async` function.
134+
> **Remember** that you can only use `await` inside an `async` function.
135135
136136
&nbsp;
137137

@@ -145,16 +145,16 @@ async function asyncFunc() {
145145

146146
try {
147147
let response = await fetch('http:your-url');
148-
} catch(err) {
149-
}
150-
console.log(err);
148+
} catch(err) {
149+
console.log(err);
150+
}
151151
}
152152

153153
asyncFunc();
154154
// TypeError: failed to fetch
155155
```
156156

157-
We use `try...catch` to grab the error but in a case where we do not have them we can still catch the error like this:
157+
We use `try...catch` to grab the error, but in a case where we do not have them we can still catch the error like this:
158158

159159

160160
``` js

0 commit comments

Comments
 (0)