Skip to content

Commit 371a4aa

Browse files
5th edition
1 parent 05bac03 commit 371a4aa

9 files changed

+489
-81
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# [The Complete Guide to Modern JavaScript ](https://leanpub.com/completeguidetomodernjavascript2020)
1212

13-
## Learn everything from the basics of JavaScript to the new ES2021 features. Practice with more than 50 quizzes and dive into the basics of TypeScript.
13+
## Learn everything from the basics of JavaScript to the new ES2022 features. Practice with more than 50 quizzes and dive into the basics of TypeScript.
1414

1515
[![book-cover](/assets/banner.jpg)](http://bit.ly/2VV2LbX)
1616

@@ -22,9 +22,9 @@ This book is **not** for total beginners, it does **cover** the basics of progra
2222

2323
 
2424

25-
## 4th Edition is out
25+
## 5th Edition is out
2626

27-
Included a new chapter detailing all the new features introduced by ES2021
27+
Included a new chapter detailing all the new features introduced by ES2022
2828

2929
## Free vs Paid Version
3030

@@ -44,13 +44,13 @@ The Paid version gives you access to:
4444
You can get the course based on this book on:
4545

4646
- [Leanpub](https://leanpub.com/c/completeguidetomodernjavascript)
47-
- [Educative](https://www.educative.io/courses/complete-guide-to-modern-javascript?aff=BqmB)
47+
- [Educative](https://www.educative.io/courses/complete-guide-to-modern-javascript?aff=BqmB) or get the complete path to become a front end develop [here](https://www.educative.io/path/become-front-end-developer?aff=BqmB)
4848

4949
You get the ebook on Amazon, Leanpub and other stores, check the following link to find your local amazon store:
5050

5151
- Play Store [Ebook](https://play.google.com/store/books/details/Alberto_Montalesi_The_Complete_Guide_to_Modern_Jav?id=avqrDwAAQBAJ)
5252
- Leanpub: [Ebook](https://leanpub.com/completeguidetomodernjavascript2020)
53-
- Amazon Global: [Paperback](https://bit.ly/2QTvHzn)
53+
- Amazon: [Paperback](https://www.amazon.com/dp/B09FNNVY1Y?ref=inspiredwebde-20)
5454

5555
If you enjoyed the book please leave a review to support me and help other buyers.
5656

ebook/03_default_function_arguments.md

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ Cannot destructure property `total` of 'undefined' or 'null'.
112112
By writing `= {}` we default our argument to an `Object` and no matter what argument we pass in the function, it will be an `Object`:
113113

114114
```javascript
115+
function calculatePrice({
116+
total = 0,
117+
tax = 0.1,
118+
tip = 0.05} = {}){
119+
return total + (total * tax) + (total * tip);
120+
}
121+
115122
calculatePrice({});
116123
// 0
117124
calculatePrice();

ebook/10_object_literal_upgrades.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ var name = "myname";
108108
var person = {};
109109
// update the object
110110
person[name] = "Alberto";
111-
console.log(person.name);
111+
console.log(person.myname);
112112
// Alberto
113113
```
114114

ebook/11_symbols.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ As we mentioned earlier, we can use them to create identifiers for object proper
4343

4444
```javascript
4545
const office = {
46-
"Tom" : "CEO",
47-
"Mark": "CTO",
48-
"Mark": "CIO",
49-
}
46+
Tom: "CEO",
47+
Mark: "CTO",
48+
Mark: "CIO",
49+
};
5050

51-
for (person in office){
51+
for (person in office) {
5252
console.log(person);
5353
}
5454
// Tom
@@ -60,12 +60,12 @@ To avoid naming collisions we can use symbols.
6060

6161
```javascript
6262
const office = {
63-
[Symbol("Tom")] : "CEO",
64-
[Symbol("Mark")] : "CTO",
65-
[Symbol("Mark")] : "CIO",
66-
}
63+
[Symbol("Tom")]: "CEO",
64+
[Symbol("Mark")]: "CTO",
65+
[Symbol("Mark")]: "CIO",
66+
};
6767

68-
for(person in office) {
68+
for (person in office) {
6969
console.log(person);
7070
}
7171
// undefined
@@ -93,6 +93,12 @@ console.log(symbols);
9393
We retrieved the array, but to be able to access the properties we have to use `map`.
9494

9595
```javascript
96+
const office = {
97+
[Symbol("Tom")] : "CEO",
98+
[Symbol("Mark")] : "CTO",
99+
[Symbol("Mark")] : "CIO",
100+
};
101+
96102
const symbols = Object.getOwnPropertySymbols(office);
97103
const value = symbols.map(symbol => office[symbol]);
98104
console.log(value);

ebook/20_ES2018_async_iteration_and_more.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Chapter 20: ES2018 Async Iteration and more?
1+
# Chapter 20: ES2018 Async Iteration and more
22

33
In this chapter we will look at what was introduced with ES2018.
44

ebook/21_ES2019_what_is_coming.md renamed to ebook/21_ES2019_string_methods_and_more.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Chapter 21: What's new in ES2019?
1+
# Chapter 21: What's new in ES2019
22

33
In this chapter we will look at what is included in the latest version of `ECMAScript`: ES2019.
44

5-
 
5+
 
66

77
## `Array.prototype.flat()` / `Array.prototype.flatMap()`
88

ebook/22_es2020_what_is_coming.md renamed to ebook/22_what_new_es2020.md

+73-62
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Chapter 22: What's coming in ES2020
1+
# Chapter 22: What's new in ES2020
22

3-
The latest version of ECMAScript, ES2020, includes many new interesting changes and we are going to cover them in this chapter.
3+
`ES2020` includes many new interesting changes and we are going to cover them in this chapter.
44

55
Not all browsers currently support these features so, I recommend you use the latest version of Chrome or Firefox to test the code examples. Otherwise, if you want to use them in your project, be sure to install a compiler like **Babel**, which at their latest version 7.8 already supports ES2020 by default so you don't need to use any plugin.
66

@@ -9,7 +9,7 @@ Not all browsers currently support these features so, I recommend you use the la
99
The support for `BigInt` means that we will be able store much larger integers in our `JavaScript`. The current max is 2^53 and you can get it by using `Number.MAX_SAFE_INTEGER`. That does not mean that you cannot store larger integer, but `JavaScript` does not handle them well, let's look at an example:
1010

1111
```javascript
12-
let num = Number.MAX_SAFE_INTEGER
12+
let num = Number.MAX_SAFE_INTEGER;
1313
// 9007199254740991
1414
num + 1;
1515
// 9007199254740992
@@ -41,12 +41,10 @@ As you can see I did not add `1` but I added `1n`, that's because you can't add
4141
This will allow you to dynamically import your modules when you need them. Look at the following example:
4242

4343
```javascript
44-
if(condition1 && condition2){
45-
const module = await import('./path/to/module.js');
46-
module.doSomething();
44+
if (condition1 && condition2) {
45+
const module = await import("./path/to/module.js");
46+
module.doSomething();
4747
}
48-
49-
5048
```
5149

5250
If you don't need a module, you don't have to import it and you can just do that when/if it's needed, using `async/await`.
@@ -59,35 +57,34 @@ Let's take these simple `Object` that represent our Users.
5957

6058
```js
6159
const user1 = {
62-
name: 'Alberto',
63-
age: 27,
64-
work: {
65-
title: 'software developer',
66-
location: 'Vietnam'
67-
}
68-
}
60+
name: "Alberto",
61+
age: 27,
62+
work: {
63+
title: "software developer",
64+
location: "Vietnam",
65+
},
66+
};
6967

7068
const user2 = {
71-
name: 'Tom',
72-
age: 27
73-
}
74-
69+
name: "Tom",
70+
age: 27,
71+
};
7572
```
7673

7774
Let's say we want to display the job title of our user.
7875
As we can see, `work` is an optional property of our `Object` so we would have to write something like this:
7976

8077
```js
8178
let jobTitle;
82-
if (user.work){
83-
jobTitle = user.work.title
79+
if (user.work) {
80+
jobTitle = user.work.title;
8481
}
8582
```
8683

8784
or using a ternary operator:
8885

8986
```js
90-
const jobTitle = user.work ? user.work.title : ''
87+
const jobTitle = user.work ? user.work.title : "";
9188
```
9289

9390
Before we access the property `title` of `work` we need to check that the user actually has a `work`.
@@ -97,7 +94,7 @@ When we are dealing with simple objects it's not such a big deal but when the da
9794
This is where the Optional Chaining `?.` operator comes to the rescue. This is how we would rewrite our code with this new operator:
9895

9996
```js
100-
const jobTitle = user.work?.title
97+
const jobTitle = user.work?.title;
10198
```
10299
103100
Done! More concise and readable.
@@ -117,31 +114,43 @@ Imagine dealing with a deeply nested object with optional properties such as the
117114
118115
```js
119116
const elon = {
120-
name: 'Elon Musk',
121-
education: {
122-
primary_school: { /* primary school stuff */ },
123-
middle_school: { /* middle school stuff */ },
124-
high_school: {/* high school stuff here */},
125-
university: {
126-
name: 'University of Pennsylvania',
127-
graduation: {
128-
year: 1995
129-
}
130-
}
131-
}
132-
}
117+
name: "Elon Musk",
118+
education: {
119+
primary_school: {
120+
/* primary school stuff */
121+
},
122+
middle_school: {
123+
/* middle school stuff */
124+
},
125+
high_school: {
126+
/* high school stuff here */
127+
},
128+
university: {
129+
name: "University of Pennsylvania",
130+
graduation: {
131+
year: 1995,
132+
},
133+
},
134+
},
135+
};
133136

134137
const mark = {
135-
name: 'Mark Zuckerberg',
136-
education: {
137-
primary_school: { /* primary school stuff */ },
138-
middle_school: { /* middle school stuff */ },
139-
high_school: {/* high school stuff here */},
140-
university: {
141-
name: 'Harvard University',
142-
}
143-
}
144-
}
138+
name: "Mark Zuckerberg",
139+
education: {
140+
primary_school: {
141+
/* primary school stuff */
142+
},
143+
middle_school: {
144+
/* middle school stuff */
145+
},
146+
high_school: {
147+
/* high school stuff here */
148+
},
149+
university: {
150+
name: "Harvard University",
151+
},
152+
},
153+
};
145154
```
146155
147156
Not all of our Users have studied in University so that property is going to be optional and the same goes for the graduation as some have dropped out and didn't finish the study.
@@ -150,8 +159,11 @@ Now imagine wanting to access the graduation year of our two users:
150159
151160
```js
152161
let graduationYear;
153-
if(
154-
user.education.university && user.education.university.graduation && user.education.university.graduation.year){
162+
if (
163+
user.education.university &&
164+
user.education.university.graduation &&
165+
user.education.university.graduation.year
166+
) {
155167
graduationYear = user.education.university.graduation.year;
156168
}
157169
```
@@ -174,14 +186,13 @@ ES6 added `Promise.all` that let us await until all the promises given to it are
174186
This means that we will be able to tell easily which one of our promises is failing:
175187
176188
```javascript
177-
178189
const arrayOfPromises = [
179-
new Promise((res, rej) => setTimeout(res, 1000)),
180-
new Promise((res, rej) => setTimeout(rej, 1000)),
181-
new Promise((res, rej) => setTimeout(res, 1000)),
182-
]
190+
new Promise((res, rej) => setTimeout(res, 1000)),
191+
new Promise((res, rej) => setTimeout(rej, 1000)),
192+
new Promise((res, rej) => setTimeout(res, 1000)),
193+
];
183194

184-
Promise.allSettled(arrayOfPromises).then(data => console.log(data));
195+
Promise.allSettled(arrayOfPromises).then((data) => console.log(data));
185196

186197
// [
187198
// Object { status: "fulfilled", value: undefined},
@@ -221,10 +232,10 @@ As you can see, all of these values are falsey. Sometimes we want to distinguish
221232
The Nullish Coalescing operator (`??`) returns the right-hand side operand when the left-hand side is nullish.
222233
223234
```javascript
224-
const x = '' ?? 'empty string';
235+
const x = "" ?? "empty string";
225236
console.log(x);
226237
// ''
227-
const num = 0 ?? 'zero';
238+
const num = 0 ?? "zero";
228239
console.log(num);
229240
// 0
230241
const n = null ?? "it's null";
@@ -246,7 +257,7 @@ The `matchAll()` method is a new string method that returns an iterator of all t
246257
```javascript
247258
// regex that matches any character in the range from 'a' to 'd'
248259
const regEx = /[a-d]/g;
249-
const str = "Lorem ipsum dolor sit amet"
260+
const str = "Lorem ipsum dolor sit amet";
250261
const regExIterator = str.matchAll(regEx);
251262

252263
console.log(Array.from(regExIterator));
@@ -265,19 +276,19 @@ As you can see, we called the `matchAll` method against our string and since our
265276
We could already do something like this:
266277
267278
```javascript
268-
import * as stuff from './test.mjs';
279+
import * as stuff from "./test.mjs";
269280
```
270281
271282
But now we can also do the same for **exports**:
272283
273284
```javascript
274-
export * as stuff from './test.mjs';
285+
export * as stuff from "./test.mjs";
275286
```
276287
277288
which would be the same as doing:
278289
279290
```javascript
280-
export { stuff }
291+
export { stuff };
281292
```
282293
283294
It's not a game-changer feature, but it adds a better symmetry between import and export statements and their syntax.
@@ -289,7 +300,7 @@ It's not a game-changer feature, but it adds a better symmetry between import an
289300
The `import.meta` object exposes information about a module, such as its URL.
290301
291302
```javascript
292-
<script type="module" src="test.js"></script>
303+
<script type="module" src="test.js"></script>;
293304
console.log(import.meta); // { url: "file:///home/user/test.js" }
294305
```
295306
@@ -305,4 +316,4 @@ You would have to manually detect the environment at runtime and bind the approp
305316
306317
Now, in ES202 you can use the `globalThis` which always refers to the `global` object. In Browsers, due to the fact, the `global` object is not directly accessible, the `globalThis` will be a reference to a `Proxy` of it.
307318
308-
Using the new `globalThis` you won't have to worry anymore about the environment in which your application is running in order to access this global value.
319+
Using the new `globalThis` you won't have to worry anymore about the environment in which your application is running in order to access this global value.

0 commit comments

Comments
 (0)