You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -21,15 +21,15 @@ Whether you are a complete beginner or you have some knowledge in JavaScript, th
21
21
22
22
After reading this book, Let Const, generators, promises and async won't be a problem anymore.
23
23
24
-
If you want to experience something new, this book also includes an introduction to the basics of TypeScript, a must-know for any JavaScript develop in 2019.
24
+
If you want to experience something new, this book also includes an introduction to the basics of TypeScript, a must-know for any JavaScript developer in 2019.
25
25
26
26
## Where to buy it
27
27
28
28
You can purchase this ebook on amazon.com at this [link](https://www.amazon.com/dp/B07S2M3FVV)
29
29
30
30
You can also read my articles on my blog [here](https://www.inspiredwebdev.com/).
31
31
32
-
The ebook includes two sections dedicated to the basics of JavaScript and TypeScript and also contains 50+ extra quizzes for your to practice and test your knowledge after reading each chapter.
32
+
The ebook includes two sections dedicated to the basics of JavaScript and TypeScript and also contains 50+ extra quizzes for you to practice and test your knowledge after reading each chapter.
33
33
You can have a look at the quizzes from the first two chapters in the `quizzes` folder.
To tell JavaScript that what's inside the curly braces is an **object literal** that we want to implicitly return, we need to wrap everything inside parenthesis.
81
+
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.
The problem in this case is that the first `this` is bound to the `const` box but the second one, inside the `setTimeout`, will be set to the `Window` object, trowing this error:
124
+
The problem in this case is that the first `this` is bound to the `const` box but the second one, inside the `setTimeout`, will be set to the `Window` object, throwing this error:
Copy file name to clipboardExpand all lines: ebook/07_iterables-and-looping.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ for (const prop of Object.keys(car)){
59
59
60
60
## The `for in` loop
61
61
62
-
Even though it is not a new ES6 loop, let's look at the `for in` loop to understand what differentiate it compared to the `for of`.
62
+
Even though it is not a new ES6 loop, let's look at the `for in` loop to understand what differentiates it to the `for of` loop.
63
63
64
64
The `for in` loop is a bit different because it will iterate over all the [enumerable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) of an object in no particular order.
65
65
@@ -103,7 +103,7 @@ for (let i of list) {
103
103
`for in` will return a list of keys whereas the `for of` will return a list of values of the numeric properties of the object being iterated.
104
104
105
105
106
-
Another differences is that we **can** stop a `for of` loop but we can't do the same with a `for in` loop.
106
+
Another difference is that we **can** stop a `for of` loop but we can't do the same with a `for in` loop.
Copy file name to clipboardExpand all lines: ebook/12_classes.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ const person = class Person {
53
53
54
54
Let's start creating our first `Class`.
55
55
56
-
We only need a method called `constructor` (remember to add only one constructor, a `SyntaxError` will be thrown if the class contains more than one constructor methods).
56
+
We only need a method called `constructor` (remember to add only one constructor, a `SyntaxError` will be thrown if the class contains more than one constructor method).
Copy file name to clipboardExpand all lines: ebook/13_promises.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -126,13 +126,13 @@ myPromise
126
126
127
127
We use `.then()` to grab the value when the promise resolves and `.catch()` when the promise rejects.
128
128
129
-
If you see our error log you can see that it tells us where the error occured, that is because we wrote `reject(Error("this is our error"));` and not simply `reject("this is our error");`.
129
+
Looking at our error log you can see that it tells us where the error occured, that is because we wrote `reject(Error("this is our error"));` and not simply `reject("this is our error");`.
130
130
131
131
132
132
133
133
### Chaining promises
134
134
135
-
We can chain promises one after the other, using what was returned from the previous one as the base for the subsequent one, whether the promise resolved or got rejected.
135
+
We can chain promises one after the other, using what was returned from the previous one as the base for the subsequent one, whether the promise was resolved or rejected.
136
136
137
137
```js
138
138
constmyPromise=newPromise((resolve, reject) => {
@@ -251,7 +251,7 @@ Our values returned together, after 1000ms (the timeout of the *second* promise)
251
251
252
252
If we were to pass an empty iterable then it will return an already resolved promise.
253
253
254
-
If one of the promise was rejected, all of them would asynchronously reject with the value of that rejection, no matter if they resolved.
254
+
If one of the promises was rejected, all of them would asynchronously reject with the value of that rejection, even if they resolved.
// one of the two promise will fail, but `.all` will return only a rejection.
264
+
// one of the two promises will fail, but `.all` will return only a rejection.
265
265
Promise
266
266
.all([promise1, promise2])
267
267
.then(data=> {
@@ -274,7 +274,7 @@ Promise
274
274
// Error: oooops error
275
275
```
276
276
277
-
`Promise.race()` on the other hand returns a promise that resolves or rejects as soon as one of the promises in the iterable resolves or reject, with the value from that promise.
277
+
`Promise.race()` on the other hand returns a promise that resolves or rejects as soon as one of the promises in the iterable resolves or rejects, with the value from that promise.
// Object { value: "I like to eat Banana", done: false }
59
+
// Object { value: "I like to eat Bananas", done: false }
60
60
fruitGenerator.next();
61
-
// Object { value: "I like to eat Apple", done: false }
61
+
// Object { value: "I like to eat Apples", done: false }
62
62
fruitGenerator.next().value;
63
-
// "I like to eat Orange"
63
+
// "I like to eat Oranges"
64
64
```
65
65
66
-
- Our new generator will loop over the array and print one value at a time every time we call `.next()`.
67
-
-if you are only concerned about getting the value, then use `.next().value` and it will not print the status of the generator
66
+
- Our new generator will loop over the array and print one value at a time every time we call `.next()`
67
+
-If you are only concerned about getting the value, then use `.next().value` and it will not print the status of the generator
68
68
69
69
70
70
@@ -113,21 +113,21 @@ myGenerator.throw("ooops");
113
113
// Object { value: undefined, done: true }
114
114
```
115
115
116
-
As you can see when we called `.throw()` the `generator` returned us the error and finished even though we still had one more `yield` to execute.
116
+
As you can see when we called `.throw()` the `generator` returned us the error and finished even though we still had one more `yield` to execute.
117
117
118
118
119
119
120
120
## Combining Generators with Promises
121
121
122
-
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*.
122
+
As we have previously seen, Promises are very useful for asynchronous programming, and by combining them with generators we have a very powerful tool at our disposal to avoid problems like the *callback hell*.
123
123
124
-
As we are solely discussing ES6, I won't be talking about async functions as they were introduce in ES2017 but know that the way they work is based on what you will see now.
124
+
As we are solely discussing ES6, I won't be talking about async functions as they were introduced in ES2017, but know that the way they work is based on what you will see now.
125
125
126
126
You can read more about async functions in Chapter 19.
127
127
128
-
Using a Generator in combination with a `Promise` will allow us to write asynchronous code that feels like synchronous.
128
+
Using a Generator in combination with a `Promise` will allow us to write asynchronous code that feels like synchronous code.
129
129
130
-
What we want to do is to wait for a promise to resolve and then pass the resolved value back into our generator in the `.next()` call.
130
+
What we want to do is wait for a promise to resolve and then pass the resolved value back into our generator in the `.next()` call.
Copy file name to clipboardExpand all lines: ebook/17_ES2016_incudes-and-exponential-operator.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Chapter 17: Everything new in ES2016
2
2
3
-
ES2016 introduced only two new features:
3
+
ES2016 introduced only two new features:
4
4
5
5
-`Array.prototype.includes()`
6
6
- The exponential operator
@@ -24,7 +24,7 @@ array.includes(3);
24
24
25
25
### Combine `includes()` with `fromIndex`
26
26
27
-
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.
27
+
We can provide `.includes()` with an index to begin searching for an element. Default is 0, but we can also pass a negative value.
28
28
29
29
The first value we pass in is the element to search and the second one is the index:
30
30
@@ -43,7 +43,7 @@ array.includes(11,-3);
43
43
// true
44
44
```
45
45
46
-
`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`.
46
+
`array.includes(5,4);` returned `false` because, despite the array actually containing 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`.
47
47
48
48
`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.
Copy file name to clipboardExpand all lines: ebook/18_ES2017_string-padding-object-entries-object-values-and-more.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Chapter 18: ES2017 string padding, `Object.entries()`, `Object.values()` and more
2
2
3
-
ES2017 introduced many new cool features, which we are going to see here.
3
+
ES2017 introduced many cool new features, which we are going to see here.
4
4
5
5
## String padding (`.padStart()` and `.padEnd()`)
6
6
@@ -13,8 +13,8 @@ We can now add some padding to our strings, either at the end (`.padEnd()`) or a
13
13
// "hello "
14
14
```
15
15
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.
16
+
We specified that we want 6 as our padding, so then why in both cases did we only get 1 space?
17
+
It happened 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.
18
18
19
19
Look at this example:
20
20
@@ -85,7 +85,7 @@ family.father;
85
85
"Jonathan Kent"
86
86
```
87
87
88
-
`Object.keys()` returned us only the keys of the object that we then had to use to access the values.
88
+
`Object.keys()` returned only the keys of the object that we then had to use to access the values.
89
89
90
90
We now have two more ways of accessing our objects:
91
91
@@ -145,7 +145,7 @@ const object = {
145
145
```
146
146
147
147
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.
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 your colleague or team members life easier.
0 commit comments