-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock.json
More file actions
620 lines (620 loc) · 44.8 KB
/
mock.json
File metadata and controls
620 lines (620 loc) · 44.8 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
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
[
{
"question": " 1. What is the output of below code",
"fullQuestion": " 1. What is the output of below code\n\n```javascript\nvar car = new Vehicle(\"Honda\", \"white\", \"2010\", \"UK\");\nconsole.log(car);\n\nfunction Vehicle(model, color, year, country) {\n this.model = model;\n this.color = color;\n this.year = year;\n this.country = country;\n}\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\n The function declarations are hoisted similar to any variables. So the placement for `Vehicle` function declaration doesn't make any difference.\n\n</p>\n"
},
"options": [
"Undefined",
"ReferenceError",
"null",
"{model: \"Honda\", color: \"white\", year: \"2010\", country: \"UK\"}"
]
},
{
"question": " 2. What is the output of below code",
"fullQuestion": " 2. What is the output of below code\n\n```javascript\nfunction foo() {\n let x = y = 0;\n x++;\n y++;\n return x;\n}\n\nconsole.log(foo(), typeof x, typeof y);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nOf course the return value of `foo()` is 1 due to the increment operator. But the statement `let x = y = 0` declares a local variable x. Whereas y declared as a global variable accidentally. This statement is equivalent to,\n\n```javascript\n let x;\n window.y = 0;\n x = window.y;\n```\n\nSince the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable `y` is available outside the function, the value is 0 and type is number.\n</p>\n"
},
"options": [
"1, undefined and undefined",
"ReferenceError: X is not defined",
"1, undefined and number",
"1, number and number"
]
},
{
"question": " 3. What is the output of below code",
"fullQuestion": " 3. What is the output of below code\n\n```javascript\nfunction main(){\n console.log('A');\n setTimeout(\n function print(){ console.log('B'); }\n ,0);\n console.log('C');\n}\nmain();\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe statements order is based on the event loop mechanism. The order of statements follows the below order,\n\n1. At first, the main function is pushed to the stack.\n2. Then the browser pushes the fist statement of the main function( i.e, A's console.log) to the stack, executing and popping out immediately.\n3. But `setTimeout` statement moved to Browser API to apply the delay for callback.\n4. In the meantime, C's console.log added to stack, executed and popped out.\n5. The callback of `setTimeout` moved from Browser API to message queue.\n6. The `main` function popped out from stack because there are no statements to execute\n7. The callback moved from message queue to the stack since the stack is empty.\n8. The console.log for B is added to the stack and display on the console.\n\n</p>\n"
},
"options": ["A, B and C", "B, A and C", "A and C", "A, C and B"]
},
{
"question": " 4. What is the output of below equality check",
"fullQuestion": " 4. What is the output of below equality check\n\n```javascript\nconsole.log(0.1 + 0.2 === 0.3);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nThis is due to the float point math problem. Since the floating point numbers are encoded in binary format, the addition operations on them lead to rounding errors. Hence, the comparison of floating points doesn't give expected results.\nYou can find more details about the explanation here [0.30000000000000004.com/](https://0.30000000000000004.com/)\n\n</p>\n"
},
"options": ["false", "true"]
},
{
"question": " 5. What is the output of below code",
"fullQuestion": " 5. What is the output of below code\n\n```javascript\nvar y = 1;\n if (function f(){}) {\n y += typeof f;\n }\n console.log(y);\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe main points in the above code snippets are,\n\n1. You can see function expression instead function declaration inside if statement. So it always returns true.\n2. Since it is not declared(or assigned) anywhere, f is undefined and typeof f is undefined too.\n\nIn other words, it is same as\n\n```javascript\nvar y = 1;\n if ('foo') {\n y += typeof f;\n }\n console.log(y);\n```\n\n**Note:** It returns 1object for MS Edge browser\n</p>\n"
},
"options": ["1function", "1object", "ReferenceError", "1undefined"]
},
{
"question": " 6. What is the output of below code",
"fullQuestion": " 6. What is the output of below code\n\n```javascript\nfunction foo() {\n return\n {\n message: \"Hello World\"\n };\n}\nconsole.log(foo());\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nThis is a semicolon issue. Normally semicolons are optional in JavaScript. So if there are any statements(in this case, return) missing semicolon, it is automatically inserted immediately. Hence, the function returned as undefined.\n\nWhereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected.\n\n```javascript\nfunction foo() {\n return {\n message: \"Hello World\"\n };\n}\nconsole.log(foo()); // {message: \"Hello World\"}\n```\n\n</p>\n"
},
"options": [
"Hello World",
"Object {message: \"Hello World\"}",
"Undefined",
"SyntaxError"
]
},
{
"question": " 7. What is the output of below code",
"fullQuestion": " 7. What is the output of below code\n\n```javascript\nvar myChars = ['a', 'b', 'c', 'd']\ndelete myChars[0];\nconsole.log(myChars);\nconsole.log(myChars[0]);\nconsole.log(myChars.length);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nThe `delete` operator will delete the object property but it will not reindex the array or change its length. So the number or elements or length of the array won't be changed.\nIf you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use `empty` instead of `undefined` to make the difference a bit clearer.\n</p>\n"
},
"options": [
"[empty, 'b', 'c', 'd'], empty, 3",
"[null, 'b', 'c', 'd'], empty, 3",
"[empty, 'b', 'c', 'd'], undefined, 4",
"[null, 'b', 'c', 'd'], undefined, 4"
]
},
{
"question": " 8. What is the output of below code in latest Chrome",
"fullQuestion": " 8. What is the output of below code in latest Chrome\n\n```javascript\nvar array1 = new Array(3);\nconsole.log(array1);\n\nvar array2 = [];\narray2[2] = 100;\nconsole.log(array2);\n\nvar array3 = [,,,];\nconsole.log(array3);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nThe latest chrome versions display `sparse array`(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation.\n**Note:** The latest version of FF displays `n empty slots` notation.\n</p>\n"
},
"options": [
"[undefined × 3], [undefined × 2, 100], [undefined × 3]",
"[empty × 3], [empty × 2, 100], [empty × 3]",
"[null × 3], [null × 2, 100], [null × 3]",
"[], [100], []"
]
},
{
"question": " 9. What is the output of below code",
"fullQuestion": " 9. What is the output of below code\n\n```javascript\nconst obj = {\n prop1: function() { return 0 },\n prop2() { return 1 },\n ['prop' + 3]() { return 2 }\n}\n\nconsole.log(obj.prop1());\nconsole.log(obj.prop2());\nconsole.log(obj.prop3());\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nES6 provides method definitions and property shorthands for objects. So both prop2 and prop3 are treated as regular function values.\n</p>\n"
},
"options": [
"0, 1, 2",
"0, { return 1 }, 2",
"0, { return 1 }, { return 2 }",
"0, 1, undefined"
]
},
{
"question": " 10. What is the output of below code",
"fullQuestion": " 10. What is the output of below code\n\n```javascript\nconsole.log(1 < 2 < 3);\nconsole.log(3 > 2 > 1);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nThe important point is that if the statement contains the same operators(e.g, < or >) then it can be evaluated from left to right.\nThe first statement follows the below order,\n\n1. console.log(1 < 2 < 3);\n2. console.log(true < 3);\n3. console.log(1 < 3); // True converted as `1` during comparison\n4. True\n\nWhereas the second statement follows the below order,\n\n1. console.log(3 > 2 > 1);\n2. console.log(true > 1);\n3. console.log(1 > 1); // False converted as `0` during comparison\n4. False\n\n</p>\n"
},
"options": [
"true, true",
"true, false",
"SyntaxError, SyntaxError,",
"false, false"
]
},
{
"question": " 11. What is the output of below code in non-strict mode",
"fullQuestion": " 11. What is the output of below code in non-strict mode\n\n```javascript\nfunction printNumbers(first, second, first) {\n console.log(first, second, first);\n}\nprintNumbers(1, 2, 3);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nIn non-strict mode, the regular JavaScript functions allow duplicate named parameters. The above code snippet has duplicate parameters on 1st and 3rd parameters.\nThe value of the first parameter is mapped to the third argument which is passed to the function. Hence, the 3rd argument overrides the first parameter.\n\n**Note:** In strict mode, duplicate parameters will throw a Syntax Error.\n</p>\n"
},
"options": [
"1, 2, 3",
"3, 2, 3",
"SyntaxError: Duplicate parameter name not allowed in this context",
"1, 2, 1"
]
},
{
"question": " 12. What is the output of below code",
"fullQuestion": " 12. What is the output of below code\n\n```javascript\nconst printNumbersArrow = (first, second, first) => {\n console.log(first, second, first);\n}\nprintNumbersArrow(1, 2, 3);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nUnlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see `SyntaxError` in the console.\n</p>\n"
},
"options": [
"1, 2, 3",
"3, 2, 3",
"SyntaxError: Duplicate parameter name not allowed in this context",
"1, 2, 1"
]
},
{
"question": " 13. What is the output of below code",
"fullQuestion": " 13. What is the output of below code\n\n```javascript\nconst arrowFunc = () => arguments.length;\nconsole.log(arrowFunc(1, 2, 3));\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nArrow functions do not have an `arguments, super, this, or new.target` bindings. So any reference to `arguments` variable tries to resolve to a binding in a lexically enclosing environment. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error.\n\nWhere as the normal function provides the number of arguments passed to the function\n\n```javascript\nconst func = function () {\n return arguments.length;\n }\nconsole.log(func(1, 2, 3));\n```\n\nBut If you still want to use an arrow function then rest operator on arguments provides the expected arguments\n\n```javascript\nconst arrowFunc = (...args) => args.length;\nconsole.log(arrowFunc(1, 2, 3));\n```\n\n</p>\n"
},
"options": [
"ReferenceError: arguments is not defined",
"3",
"undefined",
"null"
]
},
{
"question": " 14. What is the output of below code",
"fullQuestion": " 14. What is the output of below code\n\n```javascript\nconsole.log( String.prototype.trimLeft.name === 'trimLeft' );\nconsole.log( String.prototype.trimLeft.name === 'trimStart' );\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nIn order to be consistent with functions like `String.prototype.padStart`, the standard method name for trimming the whitespaces is considered as `trimStart`. Due to web web compatibility reasons, the old method name 'trimLeft' still acts as an alias for 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart'\n</p>\n"
},
"options": ["True, False", "False, True"]
},
{
"question": " 15. What is the output of below code",
"fullQuestion": " 15. What is the output of below code\n\n```javascript\nconsole.log(Math.max());\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\n-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned.\n**Note:** Zero number of arguments is a valid case.\n</p>\n"
},
"options": ["undefined", "Infinity", "0", "-Infinity"]
},
{
"question": " 16. What is the output of below code",
"fullQuestion": " 16. What is the output of below code\n\n```javascript\nconsole.log(10 == [10]);\nconsole.log(10 == [[[[[[[10]]]]]]]);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\nAs per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below\n```javascript\n10 === Number([10].valueOf().toString()) // 10\n```\nSo it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression.\n</p>\n"
},
"options": ["True, True", "True, False", "False, False", "False, True"]
},
{
"question": " 17. What is the output of below code",
"fullQuestion": " 17. What is the output of below code\n\n```javascript\nconsole.log(10 + '10');\nconsole.log(10 - '10');\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nThe concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type.\n</p>\n"
},
"options": ["20, 0", "1010, 0", "1010, 10-10", "NaN, NaN"]
},
{
"question": " 18. What is the output of below code",
"fullQuestion": " 18. What is the output of below code\n\n```javascript\nconsole.log([0] == false);\nif([0]) {\nconsole.log(\"I'm True\");\n} else {\nconsole.log(\"I'm False\");\n}\n\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nIn comparison operators, the expression `[0]` converted to Number([0].valueOf().toString()) which is resolved to false. Whereas `[0]` just becomes a truthy value without any conversion because there is no comparison operator.\n</p>\n"
},
"options": [
"True, I'm True",
"True, I'm False",
"False, I'm True",
"False, I'm False"
]
},
{
"question": " 20. What is the output of below code",
"fullQuestion": " 20. What is the output of below code\n\n```javascript\nconst numbers = new Set([1, 1, 2, 3, 4]);\nconsole.log(numbers);\n\nconst browser = new Set('Firefox');\nconsole.log(browser);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nSince `Set` object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure.\n</p>\n"
},
"options": [
"{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}",
"{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"}",
"[1, 2, 3, 4], [\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"]",
"{1, 1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}"
]
},
{
"question": " 21. What is the output of below code",
"fullQuestion": " 21. What is the output of below code\n\n```javascript\nconsole.log(NaN === NaN);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nJavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers.\n</p>\n"
},
"options": ["True", "False"]
},
{
"question": " 22. What is the output of below code",
"fullQuestion": " 22. What is the output of below code\n\n```javascript\nlet numbers = [1, 2, 3, 4, NaN];\nconsole.log(numbers.indexOf(NaN));\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe `indexOf` uses strict equality operator(===) internally and `NaN === NaN` evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always.\nBut you can use `Array.prototype.findIndex` method to find out the index of NaN in an array or You can use `Array.prototype.includes` to check if NaN is present in an array or not.\n\n```javascript\nlet numbers = [1, 2, 3, 4, NaN];\nconsole.log(numbers.findIndex(Number.isNaN)); // 4\n\nconsole.log(numbers.includes(NaN)); // true\n```\n\n</p>\n"
},
"options": ["4", "NaN", "SyntaxError", "-1"]
},
{
"question": " 23. What is the output of below code",
"fullQuestion": " 23. What is the output of below code\n\n```javascript\nlet [a, ...b,] = [1, 2, 3, 4, 5];\nconsole.log(a, b);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nWhen using rest parameters, trailing commas are not allowed and will throw a SyntaxError.\nIf you remove the trailing comma then it displays 1st answer\n\n```javascript\nlet [a, ...b] = [1, 2, 3, 4, 5];\nconsole.log(a, b); // 1, [2, 3, 4, 5]\n```\n\n</p>\n"
},
"options": [
"1, [2, 3, 4, 5]",
"1, {2, 3, 4, 5}",
"SyntaxError",
"1, [2, 3, 4]"
]
},
{
"question": " 25. What is the output of below code",
"fullQuestion": " 25. What is the output of below code\n\n```javascript\nasync function func() {\n return 10;\n}\nconsole.log(func());\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nAsync functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression,\n\n```javascript\nfunction func() {\n return Promise.resolve(10)\n}\n```\n</p>\n"
},
"options": [
"Promise {\\<fulfilled\\>: 10}",
"10",
"SyntaxError",
"Promise {\\<rejected\\>: 10}"
]
},
{
"question": " 26. What is the output of below code",
"fullQuestion": " 26. What is the output of below code\n\n```javascript\nasync function func() {\n await 10;\n}\nconsole.log(func());\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a `.then` callback. In this case, there is no return expression at the end of the function. Hence, the default return value of `undefined` is returned as the resolution of the promise. The above async function is equivalent to below expression,\n\n```javascript\nfunction func() {\n return Promise.resolve(10).then(() => undefined)\n}\n```\n</p>\n"
},
"options": [
"Promise {\\<fulfilled\\>: 10}",
"10",
"SyntaxError",
"Promise {\\<resolved\\>: undefined}"
]
},
{
"question": " 27. What is the output of below code",
"fullQuestion": " 27. What is the output of below code\n\n```javascript\nfunction delay() {\n return new Promise(resolve => setTimeout(resolve, 2000));\n}\n\nasync function delayedLog(item) {\n await delay();\n console.log(item);\n}\n\nasync function processArray(array) {\n array.forEach(item => {\n await delayedLog(item);\n })\n}\n\nprocessArray([1, 2, 3, 4]);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nEven though “processArray” is an async function, the anonymous function that we use for `forEach` is synchronous. If you use await inside a synchronous function then it throws a syntax error.\n</p>\n\n"
},
"options": ["SyntaxError", "1, 2, 3, 4", "4, 4, 4, 4", "4, 3, 2, 1"]
},
{
"question": " 28. What is the output of below code",
"fullQuestion": " 28. What is the output of below code\n\n```javascript\nfunction delay() {\n return new Promise(resolve => setTimeout(resolve, 2000));\n}\n\nasync function delayedLog(item) {\n await delay();\n console.log(item);\n}\n\nasync function process(array) {\n array.forEach(async (item) => {\n await delayedLog(item);\n });\n console.log('Process completed!');\n}\nprocess([1, 2, 3, 5]);\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions.\n\nBut you control the array sequence using for..of loop,\n\n```javascript\nasync function processArray(array) {\n for (const item of array) {\n await delayedLog(item);\n }\n console.log('Process completed!');\n}\n```\n\n</p>\n"
},
"options": [
"1 2 3 5 and Process completed!",
"5 5 5 5 and Process completed!",
"Process completed! and 5 5 5 5",
"Process completed! and 1 2 3 5"
]
},
{
"question": " 29. What is the output of below code",
"fullQuestion": " 29. What is the output of below code\n\n```javascript\nvar set = new Set();\nset.add(\"+0\").add(\"-0\").add(NaN).add(undefined).add(NaN);;\nconsole.log(set);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nSet has few exceptions from equality check,\n\n1. All NaN values are equal\n2. Both +0 and -0 considered as different values\n\n</p>\n"
},
"options": [
"Set(4) {\"+0\", \"-0\", NaN, undefined}",
"Set(3) {\"+0\", NaN, undefined}",
"Set(5) {\"+0\", \"-0\", NaN, undefined, NaN}",
"Set(4) {\"+0\", NaN, undefined, NaN}"
]
},
{
"question": " 30. What is the output of below code",
"fullQuestion": " 30. What is the output of below code\n\n```javascript\nconst sym1 = Symbol('one');\nconst sym2 = Symbol('one');\n\nconst sym3 = Symbol.for('two');\nconst sym4 = Symbol.for('two');\n\ncnsooe.log(sym1 === sym2, sym3 === sym4);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nSymbol follows below conventions,\n\n1. Every symbol value returned from Symbol() is unique irrespective of the optional string.\n2. `Symbol.for()` function creates a symbol in a global symbol registry list. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry.\n\n**Note:** The symbol description is just useful for debugging purposes.\n</p>\n\n"
},
"options": ["true, true", "true, false", "false, true", "false, false"]
},
{
"question": " 31. What is the output of below code",
"fullQuestion": " 31. What is the output of below code\n\n```javascript\nconst sym1 = new Symbol('one');\nconsole.log(sym1);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\n`Symbol` is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError\n</p>\n\n"
},
"options": ["SyntaxError", "one", "Symbol('one')", "Symbol"]
},
{
"question": " 32. What is the output of below code",
"fullQuestion": " 32. What is the output of below code\n\n```javascript\nlet myNumber = 100;\nlet myString = '100';\n\nif (!typeof myNumber === \"string\") {\n console.log(\"It is not a string!\");\n} else {\n console.log(\"It is a string!\");\n}\n\nif (!typeof myString === \"number\"){\n console.log(\"It is not a number!\")\n} else {\n console.log(\"It is a number!\");\n}\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe return value of `typeof myNumber (OR) typeof myString` is always the truthy value (either \"number\" or \"string\"). Since ! operator converts the value to a boolean value, the value of both `!typeof myNumber or !typeof myString` is always false. Hence the if condition fails and control goes to else block.\n</p>\n\n"
},
"options": [
"SyntaxError",
"It is not a string!, It is not a number!",
"It is not a string!, It is a number!",
"It is a string!, It is a number!"
]
},
{
"question": " 33. What is the output of below code",
"fullQuestion": " 33. What is the output of below code\n\n```javascript\nconsole.log(JSON.stringify({ myArray: ['one', undefined, function(){}, Symbol('')] }));\nconsole.log(JSON.stringify({ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]));\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nThe symbols has below constraints,\n\n1. The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array.\n2. All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({}).\n\n</p>\n\n"
},
"options": [
"{\"myArray\":['one', undefined, {}, Symbol]}, {}",
"{\"myArray\":['one', null,null,null]}, {}",
"{\"myArray\":['one', null,null,null]}, \"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]\"",
"{\"myArray\":['one', undefined, function(){}, Symbol('')]}, {}"
]
},
{
"question": " 34. What is the output of below code",
"fullQuestion": " 34. What is the output of below code\n\n```javascript\nclass A {\n constructor() {\n console.log(new.target.name)\n }\n}\n\nclass B extends A { constructor() { super() } }\n\nnew A();\nnew B();\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nUsing constructors, `new.target` refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor.\n</p>\n\n"
},
"options": ["A, A", "A, B"]
},
{
"question": " 35. What is the output of below code",
"fullQuestion": " 35. What is the output of below code\n\n```javascript\nconst [x, ...y,] = [1, 2, 3, 4];\nconsole.log(x, y);\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nIt throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element.\n</p>\n\n"
},
"options": ["1, [2, 3, 4]", "1, [2, 3]", "1, [2]", "SyntaxError"]
},
{
"question": " 36. What is the output of below code",
"fullQuestion": " 36. What is the output of below code\n\n```javascript\nconst {a: x = 10, b: y = 20} = {a: 30};\n\nconsole.log(x);\nconsole.log(y);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nThe object property follows below rules,\n\n1. The object properties can be retrieved and assigned to a variable with a different name\n2. The property assigned a default value when the retrieved value is `undefined`\n\n</p>\n\n"
},
"options": ["30, 20", "10, 20", "10, undefined", "30, undefined"]
},
{
"question": " 37. What is the output of below code",
"fullQuestion": " 37. What is the output of below code\n\n```javascript\nfunction area({length = 10, width = 20}) {\n console.log(length*width);\n}\n\narea();\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nIf you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Otherwise you will receive an error `Error: Cannot read property 'length' of undefined` as mentioned above.\n\nYou can avoid the error with either of the below changes,\n\n1. **Pass at least an empty object:**\n\n```javascript\nfunction area({length = 10, width = 20}) {\n console.log(length*width);\n}\n\narea({});\n```\n\n2. **Assign default empty object:**\n\n```javascript\nfunction area({length = 10, width = 20} = {}) {\n console.log(length*width);\n}\n\narea();\n```\n\n</p>\n\n"
},
"options": ["200", "Error", "undefined", "0"]
},
{
"question": " 38. What is the output of below code",
"fullQuestion": " 38. What is the output of below code\n\n```javascript\nconst props = [\n { id: 1, name: 'John'},\n { id: 2, name: 'Jack'},\n { id: 3, name: 'Tom'}\n];\n\nconst [,, { name }] = props;\nconsole.log(name);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nIt is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object.\n</p>\n\n"
},
"options": ["Tom", "Error", "undefined", "John"]
},
{
"question": " 39. What is the output of below code",
"fullQuestion": " 39. What is the output of below code\n\n```javascript\nfunction checkType(num = 1) {\n console.log(typeof num);\n}\n\ncheckType();\ncheckType(undefined);\ncheckType('');\ncheckType(null);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nIf the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter.\n\nHence, the result of function calls categorized as below,\n\n1. The first two function calls logs number type since the type of default value is number\n2. The type of '' and null values are string and object type respectively.\n\n</p>\n\n"
},
"options": [
"number, undefined, string, object",
"undefined, undefined, string, object",
"number, number, string, object",
"number, number, number, number"
]
},
{
"question": " 40. What is the output of below code",
"fullQuestion": " 40. What is the output of below code\n\n```javascript\nfunction add(item, items = []) {\n items.push(item);\n return items;\n}\n\nconsole.log(add('Orange'));\nconsole.log(add('Apple'));\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nSince the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array.\n\n</p>\n\n"
},
"options": ["['Orange'], ['Orange', 'Apple']", "['Orange'], ['Apple']"]
},
{
"question": " 41. What is the output of below code",
"fullQuestion": " 41. What is the output of below code\n\n```javascript\nfunction greet(greeting, name, message = greeting + ' ' + name) {\n console.log([greeting, name, message]);\n}\n\ngreet('Hello', 'John');\ngreet('Hello', 'John', 'Good morning!');\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nSince parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error.\n</p>\n\n"
},
"options": [
"SyntaxError",
"['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning!']"
]
},
{
"question": " 42. What is the output of below code",
"fullQuestion": " 42. What is the output of below code\n\n```javascript\nfunction outer(f = inner()) {\n function inner() { return 'Inner' }\n}\nouter();\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nThe functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i.e, `inner` is not defined).\n</p>\n\n"
},
"options": ["ReferenceError", "Inner"]
},
{
"question": " 43. What is the output of below code",
"fullQuestion": " 43. What is the output of below code\n\n```javascript\nfunction myFun(x, y, ...manyMoreArgs) {\n console.log(manyMoreArgs)\n}\n\nmyFun(1, 2, 3, 4, 5);\nmyFun(1, 2);\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nThe rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided.\n</p>\n\n"
},
"options": [
"[3, 4, 5], undefined",
"SyntaxError",
"[3, 4, 5], []",
"[3, 4, 5], [undefined]"
]
},
{
"question": " 44. What is the output of below code",
"fullQuestion": " 44. What is the output of below code\n\n```javascript\nconst obj = {'key': 'value'};\nconst array = [...obj];\nconsole.log(array);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nSpread syntax can be applied only to iterable objects. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as `map(), reduce(), and assign()`. If you still try to do it, it still throws `TypeError: obj is not iterable`.\n</p>\n\n"
},
"options": ["['key', 'value']", "TypeError", "[]", "['key']"]
},
{
"question": " 45. What is the output of below code",
"fullQuestion": " 45. What is the output of below code\n\n```javascript\nfunction* myGenFunc() {\n yield 1;\n yield 2;\n yield 3;\n}\nvar myGenObj = new myGenFunc;\nconsole.log(myGenObj.next().value);\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nGenerators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"\n\n</p>\n\n"
},
"options": ["1", "undefined", "SyntaxError", "TypeError"]
},
{
"question": " 46. What is the output of below code",
"fullQuestion": " 46. What is the output of below code\n\n```javascript\n\nfunction* yieldAndReturn() {\n yield 1;\n return 2;\n yield 3;\n}\n\nvar myGenObj = yieldAndReturn()\nconsole.log(myGenObj.next());\nconsole.log(myGenObj.next());\nconsole.log(myGenObj.next());\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n\nA return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: `{value: undefined, done: true}`.\n</p>\n\n"
},
"options": [
"{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }",
"{ value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }",
"{ value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }",
"{ value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }"
]
},
{
"question": " 47. What is the output of below code",
"fullQuestion": " 47. What is the output of below code\n\n```javascript\nconst myGenerator = (function *(){\n yield 1;\n yield 2;\n yield 3;\n})();\nfor (const value of myGenerator) {\n console.log(value);\n break;\n}\n\nfor (const value of myGenerator) {\n console.log(value);\n}\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nThe generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break & return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.\n</p>\n\n"
},
"options": ["1,2,3 and 1,2,3", "1,2,3 and 4,5,6", "1 and 1", "1"]
},
{
"question": " 48. What is the output of below code",
"fullQuestion": " 48. What is the output of below code\n\n```javascript\nconst num = 0o38;\nconsole.log(num);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\nIf you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.\n</p>\n\n"
},
"options": ["SyntaxError", "38"]
},
{
"question": " 49. What is the output of below code",
"fullQuestion": " 49. What is the output of below code\n\n```javascript\nconst squareObj = new Square(10);\nconsole.log(squareObj.area);\n\nclass Square {\n constructor(length) {\n this.length = length;\n }\n\n get area() {\n return this.length * this.length;\n }\n\n set area(value) {\n this.area = value;\n }\n}\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nUnlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".\n\n**Note:** Class expressions also applies to the same hoisting restrictions of class declarations.\n</p>\n\n"
},
"options": ["100", "ReferenceError"]
},
{
"question": " 50. What is the output of below code",
"fullQuestion": " 50. What is the output of below code\n\n```javascript\nfunction Person() { }\n\nPerson.prototype.walk = function() {\n return this;\n}\n\nPerson.run = function() {\n return this;\n}\n\nlet user = new Person();\nlet walk = user.walk;\nconsole.log(walk());\n\nlet run = Person.run;\nconsole.log(run());\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\n\nWhen a regular or prototype method is called without a value for **this**, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial `this` value is undefined so both methods return window objects.\n\n</p>\n\n"
},
"options": [
"undefined, undefined",
"Person, Person",
"SyntaxError",
"Window, Window"
]
},
{
"question": " 51. What is the output of below code",
"fullQuestion": " 51. What is the output of below code\n\n```javascript\nclass Vehicle {\n constructor(name) {\n this.name = name;\n }\n\n start() {\n console.log(`${this.name} vehicle started`);\n }\n}\n\nclass Car extends Vehicle {\n start() {\n console.log(`${this.name} car started`);\n super.start();\n }\n}\n\nconst car = new Car('BMW');\nconsole.log(car.start());\n```\n\n",
"answer": {
"index": 3,
"full": "\n<p>\n\n##### Answer: 3\n\nThe super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.\n\n</p>\n\n"
},
"options": [
"SyntaxError",
"BMW vehicle started, BMW car started",
"BMW car started, BMW vehicle started",
"BMW car started, BMW car started"
]
},
{
"question": " 52. What is the output of below code",
"fullQuestion": " 52. What is the output of below code\n\n```javascript\nconst USER = {'age': 30};\nUSER.age = 25;\nconsole.log(USER.age);\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\n\nEven though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.\n</p>\n\n"
},
"options": ["30", "25", "Uncaught TypeError", "SyntaxError"]
},
{
"question": " 53. What is the output of below code",
"fullQuestion": " 53. What is the output of below code\n\n```javascript\nconsole.log('🙂' === '🙂');\n```\n\n",
"answer": {
"index": 2,
"full": "\n<p>\n\n##### Answer: 2\nEmojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.\n\n</p>\n\n"
},
"options": ["false", "true"]
},
{
"question": " 54. What is the output of below code?",
"fullQuestion": " 54. What is the output of below code?\n\n```javascript\nconsole.log(typeof typeof typeof true);\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\nThe typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.\n</p>\n\n"
},
"options": ["string", "boolean", "NaN", "number"]
},
{
"question": " 55. What is the output of below code?",
"fullQuestion": " 55. What is the output of below code?\n\n```javascript\nlet zero = new Number(0);\n\nif (zero) {\n console.log(\"If\");\n} else {\n console.log(\"Else\");\n}\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n1. The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object. \n2. Objects are always truthy in if block\n\nHence the above code block always goes to if section.\n\n</p>\n\n"
},
"options": ["If", "Else", "NaN", "SyntaxError"]
},
{
"question": " 55. What is the output of below code in non strict mode?",
"fullQuestion": " 55. What is the output of below code in non strict mode?\n\n```javascript\nlet msg = \"Good morning!!\";\n\nmsg.name = \"John\"; \n\nconsole.log(msg.name);\n```\n\n",
"answer": {
"index": 4,
"full": "\n<p>\n\n##### Answer: 4\nIt returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.\n</p>\n\n"
},
"options": ["\"\"", "Error", "John", "Undefined"]
},
{
"question": " 56. What is the output of below code?",
"fullQuestion": " 56. What is the output of below code?\n\n```javascript\nlet count = 10;\n\n(function innerFunc() {\n if (count === 10) {\n let count = 11;\n console.log(count);\n }\n console.log(count);\n})();\n```\n\n",
"answer": {
"index": 1,
"full": "\n<p>\n\n##### Answer: 1\n11 and 10 is logged to the console. \n\nThe innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable `count` which overwrites the ourter `count` variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.\n \n</p>\n\n"
},
"options": ["11, 10", "11, 11", "10, 11", "10, 10"]
}
]