-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
384 lines (265 loc) · 6.23 KB
/
index.js
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
//: 1.What's the output?
function sayHi() {
console.log(name);
console.log(age);
var name = "Ankit";
let age = 18;
}
sayHi();
//: 2.What's the output?
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
//: 3.What's the output?
const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius,
};
//: 4.What's the output?
+true;
!"Ankit";
//: 5.What's the output?
const bird = {
size: "small",
};
const mouse = {
name: "Mickey",
small: true,
};
console.log(mouse.bird.size);
console.log(mouse[bird.size]);
console.log(mouse[bird["size"]]);
//: 6.What's the output?
let c = { greeting: "Hey!" };
let d;
d = c;
c.greeting = "Hello!";
console.log(d.greeting);
//: 7.What's the output?
let a = 3;
let b = new Number(3);
let x = 3;
console.log(a == b);
console.log(a === b);
console.log(b === b);
//: 8.What's the output?
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor;
return this.newColor;
}
constructor({ newColor = "green" } = {}) {
this.newColor = newColor;
}
}
const freddie = new Chameleon({ newColor: "purple" });
console.log(freddie.colorChange("orange"));
//: 9.What's the output?
let greeting;
greetign = {};
console.log(greetign);
//: 10.What happens when we do this?
function bark() {
console.log("Woof!");
}
bark.animal = "dog";
//: 11.What the output?
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const member = new Person("Ankit", "Yadav");
Person.getFullName = function () {
return `${this.firstName} ${this.lastName}`;
};
console.log(member.getFullName());
// 12.What's the output?
function Person2(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const ankit = new Person2("Ankit", "Yadav");
const ram = Person2("Ram", "Yadav");
console.log(ankit);
console.log(ram);
//: 13.What are the three phase of event propagation?
// => Target > Capturing > Bubbling
// => Bubbling > Taget > Capturing
// => Taget > Bubbling > Capturing
// => Capturing > Target > Bubbling
//: 14.All object have prototypes
// => True
// => False
//: 14.What's the output?
function sum(a, b) {
return a + b;
}
sum(1, "2");
//: 16.What's the output?
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
//: 17.What's the output?
function getPerson(one, two, three) {
console.log(one);
console.log(two);
console.log(three);
}
const user = "Ankit";
const age = 18;
getPerson`${user} is ${age} years old`;
//: What's the output?
function checkAge(data) {
if (data === { age: 18 }) {
console.log("You are an adult!");
}
if (data == { age: 18 }) {
console.log("You can still be adult!");
} else {
console.log("Hmm... You don't have an age I guess");
}
}
checkAge({ age: 18 });
//: 19.What's the output
function getAge(...args) {
console.log(typeof args);
}
getAge(21);
//: 20 What's the output?
function getName() {
"use strict";
name = "Ankit";
console.log(name);
}
getName();
//: 21.What's the value of sum?
const sum = eval("10*10+5");
//: 22.How long is cool_secret accessible?
sessionStorage.setItem("cool_secret", 123);
//: 23.What's the output?
var num = 8;
var num = 10;
console.log(num);
//: 24.What the output?
const obj = { 1: "a", 2: "b", 3: "c" };
const set = new Set([1, 2, 3, 4]);
obj.hasOwnProperty("1");
obj.hasOwnProperty(1);
set.has("1");
set.has(1);
// 25.What's the output?
const objj = { a: one, b: two, a: three };
console.log(objj);
//: The JavaScript global execution context creates two things for you: the global object and the "this" keyword
//: 27.What's the output?
for (let i = 1; i < 5; i++) {
if (i === 3) continue;
console.log(i);
}
//: 28.What's the output?
String.prototype.giveAnkitPizza = () => {
return `Just give Ankit Pizza already!`;
};
const name = "Ankit";
console.log(name.giveAnkitPizza());
//: 29.What's the output?
const w = {};
const y = { key: "b" };
const z = { key: "c" };
w[y] = 123;
w[z] = 456;
console.log(w[y]);
//: 30.What's the output?
const foo = () => console.log("First");
const bar = () => setTimeout(() => console.log("Second"));
const baz = () => console.log("Third");
//: 31.What is the event.target when clicking the button?
<div onclick="console.log('first div')">
<div onclick="console.log('second div')">
<button onclick="console.log('button')">Click!</button>
</div>
</div>;
//: 32.When you click the paragraph, what's the logged output?
<div onclick="console.log('div')">
<p onclick="console.log('p')">Click here!</p>
</div>;
//: 33:What's the output?
const person = { name: "Ankit" };
function sayHi(age) {
return `${this.name} is ${age}`;
}
console.log(sayHi.call(person, 21));
console.log(sayHi.bind(person, 21));
//: 34.What's the output?
function sayHello() {
return (() => 0)();
}
console.log(typeof sayHi());
//: 35.Which of these values are falsy?
0;
new Number(0);
("");
(" ");
new Boolean(false);
undefined;
//: 36.What's the output?
console.log(typeof typeof 1);
//: 37.What's the output?
const numbers = [1, 2, 3];
numbers[10] = 11;
console.log(numbers);
//: 38.What's the output?
(() => {
let x, y;
try {
throw new Error();
} catch (x) {
(x = 1), (y = 2);
console.log(x);
}
console.log(x);
console.log(y);
})();
//: 39.Everything in JavaScript is either a...
//: 40.What's the output?
[
[0, 1],
[2, 3],
].reduce(
(acc, cur) => {
acc.concat(cur);
},
[1, 2] // => initial value
);
//: 41:What's the output?
!!null;
!!"";
!!1;
//: 42.What does the setInterval method return in the browser?
setInterval(() => console.log("Hi", 1000));
//: 43.What does this return?
[..."Ankit"];
//: 44: What's the output?
function* generator(i) {
yield 1;
yield i * 2;
}
const gen = generator(10);
console.log(gen.next().value);
console.log(gen.next().value);
//: 45.What does this return?
const firstPromise = new Promise((resolve, reject) => {
setTimeout(resolve, 500, "one");
});
const secondPromise = new Promise((resolve, reject) => {
setTimeout(resolve, 100, "two");
});
Promise.race([firstPromise, secondPromise]).then((res) => console.log(res));
//: 46.What the Output?