-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.js
More file actions
161 lines (107 loc) · 2.95 KB
/
Test.js
File metadata and controls
161 lines (107 loc) · 2.95 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Question series
http://perfectionkills.com/javascript-quiz-es6/
*/
var t =(function(x, f = () => x) {
var x;
var y = x;
x = 2;
return [x, y, f()];
})(1)
console.log(t); // 2,1,1
// Q2 ------------------
var t2 = (function() {
return [
(() => this.x).bind({ x: 'inner' })(),
(() => this.x)()
]
}).call({ x: 'outer' });
console.log(t2);
// working for genaric functions
var f = function(){
console.log(this.name);
}
var fboud =f.bind({name: "Koli"});
fboud();
// IIFE
((function(){
console.log(this.x);
}).bind({x:90}))();
// but when it is comes to the arrow functions, this dowsn't work
((()=>{
console.log(this.x); // undefined
}).bind({x : 80}))();
// but when it is in the scope bbound with other object
((function(){
((()=>{
console.log(this.x); // 60
}).bind({x : 80}))();
}).bind({x:60}))();
// without bounded object
(function(){
var x = 20;
((()=>{
console.log(this.x); // undefined
console.log(x); // 20
}).bind({x : 80}))();
})();
// sothat t2 will get ['outer','outer']
//Q3--------------------
var t4 =(function() {
let f = this ? class g { } : class h { };
return [
typeof f,
typeof h
];
})();
console.log(t4);
//[function, undefined]
// we dont know the h but f is s function
// Q4 ----------------
console.log((typeof (new (class { class () {} })))); // object
console.log(typeof (new (class F extends (String, Array) { })).substring); // undefined read inside variable
// calling internal values , in the upper example , substring has not defined.
var cl = new (class F extends (String, Array) { substring(){} });
console.log(typeof(cl.substring));
//Q7 --------------
console.log([...[...'...']].length);
/*
answer is 3 because ... is an stiring with 3 letters.
[...'...'] is 3 length array
*/
// Q8 -----------
//console.log(typeof (function* f() { yield f })().next().next())
// Error
// var rf = (function* f() { yield f })().next(); // return f genarator function
// var fs = rf.value; // value is a genarator fucntion type not the function
// console.log(fs.next()); // but this fs will not be a function.
console.log(typeof `${{Object}}`.prototype);
//Q 11
//((...x, xs)=>x)(1,2,3) // Error ...x(Rest params must be at the last)
// Q 12
let arr = [ ];
for (let { x = 2, y } of [{ x: 1 }, 2, {y:10},[2,3]]) {
arr.push(x, y);
}
console.log(arr); // Error
/*
{x=2,y} of {x:1} // x goes to 1 and y doesnt defined. {1, undefined}
{x=2,y} of 2 // x goes to 2 and y variable cannot find {2, undefined}
{x=2,y} of {y} // in this object y is not initialozed and defined. so that error
{x=2,y} of {x:1,y:7} // x=1, y=7
{x=2,y} of (2,3) // x=2, y undefined.
{x=2,y} of {y:1} // x =2 (default), y =1
*/
// Q 13 ---------------
(function(){
if(false){
// let f ={ g() => {}}; Syntax Error (g()=> {})
}
})();
// correction
(function(){
if(false){
let f = { g: () => 1};
}
return typeof f;
})();