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: ebook/01_var_let_const.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,6 @@ As you can see, when we assigned a new value to our `let` inside our block-scope
70
70
71
71
Similarly to `let`, `const` are **block-scoped**, but they differ in the fact that their value **can't change through re-assignment or can't be re-declared**.
72
72
73
-
74
73
```javascript
75
74
constconstant='I am a constant';
76
75
constant =" I can't be reassigned";
@@ -100,7 +99,7 @@ In this case we are not reassigning the whole variable but just one of its prope
100
99
101
100
---
102
101
103
-
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)
104
103
105
104
```javascript
106
105
constperson= {
@@ -160,7 +159,6 @@ The first opinion comes from [Mathias Bynes:](https://mathiasbynens.be/notes/es6
160
159
- use `let` only if rebinding is needed.
161
160
-`var` should never be used in ES6.
162
161
163
-
164
162
The second opinion comes from [Kyle Simpson:](https://me.getify.com/)
165
163
166
164
- Use `var` for top-level variables that are shared across many (especially larger) scopes.
Both functions achieve the same result, but the new syntax allows you to be more concise.
59
-
Beware! Readability is more important than conciseness so you might want to write your funciton like this if you are working in a team and not everybody is totally up-to-date with ES6.
59
+
Beware! Readability is more important than conciseness so you might want to write your function like this if you are working in a team and not everybody is totally up-to-date with ES6.
60
60
61
61
```js
62
62
constarrowFunction= (name) => {
@@ -106,10 +106,10 @@ When you use an arrow function, the `this` keyword is inherited from the parent
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/05_additional_string_methods.md
+40-33Lines changed: 40 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,46 +2,53 @@
2
2
3
3
There are many methods that we can use against strings. Here's a list of a few of them:
4
4
5
-
1.**indexOf()**
6
-
7
-
Gets the position of the first occurence of the specified value in a string.
8
-
```js
9
-
conststr="this is a short sentence";
10
-
str.indexOf("short");
11
-
// Output: 10
12
-
```
13
-
2.**slice()**
14
-
15
-
Pulls a specified part of a string as a new string.
16
-
```js
17
-
conststr="pizza, orange, cereals"
18
-
str.slice(0, 5);
19
-
// Output: "pizza"
20
-
```
21
-
3.**toUpperCase()**
22
-
23
-
Turns all characters of a string to uppercase.
24
-
```js
25
-
conststr="i ate an apple"
26
-
str.toUpperCase()
27
-
// Output: "I ATE AN APPLE"
28
-
```
29
-
4.**toLowerCase()**
30
-
31
-
Turns all characters of a string to lowercase.
32
-
```
33
-
const str = "I ATE AN APPLE"
34
-
str.toLowerCase()
35
-
// Output: "i ate an apple"
36
-
```
5
+
1.**indexOf()**
6
+
7
+
Gets the position of the first occurrence of the specified value in a string.
8
+
9
+
```js
10
+
conststr="this is a short sentence";
11
+
str.indexOf("short");
12
+
// Output: 10
13
+
```
14
+
15
+
2.**slice()**
16
+
17
+
Pulls a specified part of a string as a new string.
18
+
19
+
```js
20
+
conststr="pizza, orange, cereals"
21
+
str.slice(0, 5);
22
+
// Output: "pizza"
23
+
```
24
+
25
+
1.**toUpperCase()**
26
+
27
+
Turns all characters of a string to uppercase.
28
+
29
+
```js
30
+
conststr="i ate an apple"
31
+
str.toUpperCase()
32
+
// Output: "I ATE AN APPLE"
33
+
```
34
+
35
+
4.**toLowerCase()**
36
+
37
+
Turns all characters of a string to lowercase.
38
+
39
+
```JS
40
+
conststr="I ATE AN APPLE"
41
+
str.toLowerCase()
42
+
// Output: "i ate an apple"
43
+
```
37
44
38
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.
Copy file name to clipboardExpand all lines: ebook/12_classes.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@
3
3
Quoting MDN:
4
4
> classes are primarily syntactical sugar over js's existing prototype-based inheritance. The class syntax **does not** introduce a new object-oriented inheritance model to JavaScript.
5
5
6
-
7
6
That being said, let's review prototypal inheritance before we jump into classes.
8
7
9
8
```js
@@ -83,7 +82,7 @@ As you can see everything works just like before. As we mentioned at the beginni
83
82
84
83
## Static methods
85
84
86
-
Right now the two new methods that we created, `greet()` and `farewell()` can be accessed by every new instance of `Person`, but what if we want a method that can only be accessed by the class itself, similarily to `Array.of()` for arrays?
85
+
Right now the two new methods that we created, `greet()` and `farewell()` can be accessed by every new instance of `Person`, but what if we want a method that can only be accessed by the class itself, similarly to `Array.of()` for arrays?
87
86
88
87
```js
89
88
staticinfo(){
@@ -135,7 +134,6 @@ alberto.nicknames;
135
134
136
135
What if we want to have a new `Class` that inherits from our previous one? We use `extends`:
137
136
138
-
139
137
```js
140
138
// our initial class
141
139
classPerson {
@@ -179,7 +177,7 @@ class Adult extends Person {
179
177
}
180
178
```
181
179
182
-
Why did we set `super(name,age)` ? Because our `Adult` class inherits name and age from the `Person` therefore we don't need to redeclare them.
180
+
Why did we set `super(name,age)` ? Because our `Adult` class inherits name and age from the `Person` therefore we don't need to redeclare them.
183
181
Super will simply create a new Person for us.
184
182
185
183
If we now run the code again we will get this:
@@ -203,7 +201,7 @@ We want to create something like this, something similar to an array where the f
203
201
204
202
```js
205
203
// we create a new Classroom
206
-
constmyClass=newClassroom('1A',[
204
+
constmyClass=newClassroom('1A',[
207
205
{name:"Tim", mark:6},
208
206
{name:"Tom", mark:3},
209
207
{name:"Jim", mark:8},
@@ -221,12 +219,12 @@ class Classroom extends Array {
Copy file name to clipboardExpand all lines: ebook/13_promises.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ fs.readdir(source, function (err, files) {
52
52
53
53
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.
54
54
55
-
To improve your callbacks you can check out http://callbackhell.com/
55
+
To improve your callbacks you can check out [http://callbackhell.com/](http://callbackhell.com/)
56
56
57
57
Here we will focus on how to write promises.
58
58
@@ -191,7 +191,7 @@ We did not get "first value" because we threw an error therefore we only got the
0 commit comments