Skip to content

Commit 6407324

Browse files
add quiz chapter 1 and 2
1 parent 1c75bc7 commit 6407324

File tree

4 files changed

+109
-4
lines changed

4 files changed

+109
-4
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Additional chapters cover the new features introduced post ES6 (ES2015) all the
2323

2424
## Download
2525

26-
Download the ebook in PDF or EPUB format from [here](https://github.com/AlbertoMontalesi/JavaScript-es6-and-beyond-ebook/releases)
2726

2827
## About me
2928

ebook/02_arrow_functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ greeting("Tom");
8484

8585
## Arrow function and the `this` keyword
8686

87-
You need to be careful when using arrow functions in conjunction with the this keyword, as they behave differently from normal functions.
87+
You need to be careful when using arrow functions in conjunction with the `this` keyword, as they behave differently from normal functions.
8888

8989
When you use an arrow function, the `this` keyword is inherited from the parent scope.
9090

@@ -151,8 +151,8 @@ const person = {
151151
age: 10,
152152
grow: () => {
153153
// error: *this* refers to the window
154-
this.age++,
155-
},
154+
this.age++;
155+
}
156156
}
157157
```
158158

quizzes/01_var_let_const.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Chapter 1: Var vs Let vs Const & the temporal dead zone
2+
3+
## End of chapter quiz
4+
5+
1) What is the correct output of this code?
6+
7+
```js
8+
var greeting = "Hello";
9+
10+
greeting = "Farewell";
11+
12+
for (var i = 0; i < 2; i++) {
13+
var greeting = "Goodmorning";
14+
}
15+
16+
console.log(greeting);
17+
```
18+
19+
- [] Hello
20+
- [*] Goodmorning
21+
- [] Farewell;
22+
23+
&nbsp;
24+
25+
2) What is the correct output of this code?
26+
27+
28+
```js
29+
let value = 1;
30+
31+
if(true) {
32+
let value = 2;
33+
console.log(value);
34+
}
35+
36+
value = 3;
37+
```
38+
39+
- [] 1
40+
- [*] 2
41+
- [] 3
42+
43+
44+
3) What is the correct output of this code?
45+
46+
```js
47+
console.log(constant);
48+
49+
const constant = 1;
50+
```
51+
52+
- [] undefined
53+
- [*] ReferenceError
54+
- 1
55+

quizzes/02_arrow_functions.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Chapter 2: Arrow functions
2+
3+
## End of chapter quiz
4+
5+
1) What is the correct syntax for an arrow function?
6+
7+
```js
8+
let arr = [1,2,3];
9+
10+
a)
11+
let func = arr.map(n -> n+1);
12+
13+
b)
14+
let func = arr.map(n => n+1);
15+
16+
c)
17+
let func = arr.map(n ~> n+1);
18+
```
19+
20+
- [] a
21+
- [] b
22+
- [*] c
23+
24+
25+
> The correct syntax for an arrow function is the so called fat arrow `=>`
26+
27+
&nbsp;
28+
29+
30+
// example with this keyword
31+
32+
2) What is the correct output of this code?
33+
34+
``` js
35+
const person = {
36+
age: 10,
37+
grow: () => {
38+
this.age++;
39+
},
40+
}
41+
person.grow();
42+
43+
console.log(person.age);
44+
```
45+
46+
- [*] 10
47+
- [] 11
48+
- [] undefined
49+
50+
> Inside an arrow function, the `this` keyword inherits from its parent scope which in this case it's the window, therefore the `age` remains 10.
51+

0 commit comments

Comments
 (0)