Some JS Concept Questions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
this.x = -1
let x = 1

let objInObj = {
x: 10,
obj: {
x: 100,
f: () => {
console.log(this.x);
this.x = 1000; // <- Note this change might reflect later...
}
}
}

class objInClass {
x = 10;
constructor() {
this.x = 100;
this.obj = {
f: () => function () { console.log(this.x); }
}
}
}


class funcInClass {
x = 10;
obj() {
let x = 100;
let f = () => { console.log(this.x); };
return f;
}
}

class objInClass2 {
x = 10;
constructor() {
let x = 1000;
this.obj = {
f: () => console.log(this.x)
}
}
}

let objInObj2 = {
x: 10,
obj: {
f: function () { this.x.foo(); },
x: {
foo: () => console.log(this.x)
}
}
}

objInObj.obj.f(); // <- A
(new objInClass()).obj.f(); // <- B
new funcInClass().obj()(); // <- C
(new objInClass2()).obj.f(); // <- D
objInObj2.obj.f(); // <- E

Question: What are the values printed at A, B, C, D, and E, respectively?