-
-
Notifications
You must be signed in to change notification settings - Fork 359
/
javascript-quiz.ts
2122 lines (2117 loc) · 93.2 KB
/
javascript-quiz.ts
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const javascriptQuiz = [
{
Question:
"In JavaScript, if let x='Prakhar', then what will be the result for console.log(x.substring(2,5))?",
Answer: "akh",
Distractor1: "akaha",
Distractor2: "aka",
Distractor3: "akkkaha",
Explanation:
"The first parameter in the substring method represents the starting index for the string while the second parameter represents the ending index.",
Link: "https://www.freecodecamp.org/news/javascript-substring-examples-slice-substr-and-substring-methods-in-js/"
},
{
Question:
"In JavaScript, what is the range of numbers returned from the Math.random() method?",
Answer: "Between 0 and 1 (including 0; not including 1).",
Distractor1: "Between 0 and 1 (including neither 0 or 1).",
Distractor2: "Between 0 and 1 (including 1; not including 0).",
Distractor3: "Between 0 and 100 (including 0; not including 100).",
Explanation:
"Math.random() returns a floating point (decimal) number that is less than one and greater than or equal to zero.",
Link: "https://www.freecodecamp.org/news/javascript-math-random-method-explained/"
},
{
Question:
"In JavaScript, what is the difference between the indexOf() and search() methods?",
Answer: "indexOf() can take a second parameter while search() cannot",
Distractor1: "Both methods are the same",
Distractor2: "indexOf() only takes regular expressions",
Distractor3: "The search() method runs 4x faster than the indexOf() method",
Explanation:
"One key difference between the indexOf() and search() methods is that indexOf() can take a second parameter while search() cannot.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf"
},
{
Question: "What does the 'debugger' statement in JavaScript do?",
Answer: "It acts as a breakpoint in a program",
Distractor1: "It will debug errors in the current statement",
Distractor2: "It will debug all the errors in the program at runtime",
Distractor3: "All of the above",
Explanation:
"The 'debugger' statement is used to setup the breakup points at probable points of errors in the code snippet, using the debugger window.",
Link: "https://www.freecodecamp.org/news/debugging-javascript-for-beginners-5d4ac15dd1cd/#"
},
{
Question: "What kind of programming can JavaScript be used for?",
Answer: "Both Client and Server side programming",
Distractor1: "Server side only",
Distractor2: "Client side only",
Distractor3: "None of these options",
Explanation:
"JavaScript is a programming language which can be used on the client and server side.",
Link: "https://developer.mozilla.org/en-US/docs/Learn/Server-side/First_steps/Introduction#are_server-side_and_client-side_programming_the_same"
},
{
Question:
"In JavaScript, if let x='5', then what will be the value of console.log(x==5,x===5)?",
Answer: "true false",
Distractor1: "true true",
Distractor2: "false true",
Distractor3: "false false",
Explanation:
"== compares only the value while === compares the value as well as the type.",
Link: "https://www.freecodecamp.org/news/javascript-triple-equals-sign-vs-double-equals-sign-comparison-operators-explained-with-examples/"
},
{
Question:
"In JavaScript, which Web API is used to display a dialog box with an optional message?",
Answer: "window.alert()",
Distractor1: "window.alertHTML()",
Distractor2: "window.alertContent()",
Distractor3: "window.alertBox()",
Explanation:
"In Javascript, the window.alert() method is used to display a dialog box with an optional message",
Link: "https://www.freecodecamp.org/news/how-to-build-a-javascript-alert-box-or-popup-window/"
},
{
Question:
"In JavaScript, if let word='Intelligent', then what will be the value of word.slice(2,5)?",
Answer: "tel",
Distractor1: "tellig",
Distractor2: "ll",
Distractor3: "Inigent",
Explanation:
"The slice() method returns a substring of the original string. The original string remains untouched.",
Link: "https://www.freecodecamp.org/news/javascript-substring-examples-slice-substr-and-substring-methods-in-js/"
},
{
Question:
"In Javascript, what keyword is used to check whether a given property in an object is valid?",
Answer: "in",
Distractor1: "is in",
Distractor2: "exists",
Distractor3: "lies",
Explanation:
"The in keyword is used to check whether the given property in an object is valid or not.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in"
},
{
Question:
"In JavaScript, which method uses a callback function for each element in the array?",
Answer: "forEach()",
Distractor1: "every(",
Distractor2: "forEvery()",
Distractor3: "each()",
Explanation:
"The forEach() method uses a callback function for each element in the array.",
Link: "https://www.freecodecamp.org/news/javascript-foreach-how-to-loop-through-an-array-in-js/"
},
{
Question:
"Which of the following JavaScript array methods would run the slowest in a worst-case scenario?",
Answer: "shift()",
Distractor1: "pop()",
Distractor2: "push()",
Distractor3: "All take about the same time on an array of the same size.",
Explanation:
"shift() removes elements from the front of the array, which means the entire array needs to be re-indexed. In contrast, pop() and push() both work from the 'back' of the array and don't require re-indexing.",
Link: "https://www.freecodecamp.org/news/the-complexity-of-simple-algorithms-and-data-structures-in-javascript-11e25b29de1e/"
},
{
Question:
"In JavaScript, what will be the result for the following code: 12345.6789.toFixed()?",
Answer: "12346",
Distractor1: "12345",
Distractor2: "12345.6789",
Distractor3: "Undefined. toFixed() must take parameters",
Explanation:
"Parameters are optional. If not passed, it will round the given number, leaving with no fractional part",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed#examples"
},
{
Question:
"What is the process of converting a value from one data type to another called?",
Answer: "Type Coercion",
Distractor1: "Type Casting",
Distractor2: "Data Converting",
Distractor3: "Change Value",
Explanation:
"Type coercion is the process of converting a value from one type to another (such as a string to number, object to boolean, and so on).",
Link: "https://www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/"
},
{
Question: "Which web API method cancels an event's default behavior?",
Answer: "preventDefault()",
Distractor1: "cancel()",
Distractor2: "preVent()",
Distractor3: "stop()",
Explanation:
"The preventDefault() method cancels the event and prevents the browser from running its default action.",
Link: "https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault"
},
{
Question:
"Which of the following methods allows you to set up functions to be called when a specified event happens, such as when a user clicks a button?",
Answer: "addEventListener()",
Distractor1: "listenEvent()",
Distractor2: "callEvent()",
Distractor3: "eventWake()",
Explanation:
"The JavaScript addEventListener() method allows you to set up functions to be called when a specified event happens, such as when a user clicks a button.",
Link: "https://www.youtube.com/watch?v=jS4aFq5-91M&t=17471s"
},
{
Question:
"In JavaScript, which Web API is used to insert a child node anywhere under the parent node?",
Answer: "insertBefore()",
Distractor1: "prepend()",
Distractor2: "append()",
Distractor3: "lookupPrefix()",
Explanation:
"The insertBefore() method inserts a new child node anywhere under the parent node. This method has two parameters: newNode and referenceNode",
Link: "https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore"
},
{
Question:
"In JavaScript, which property of an element allows you to get or set the HTML markup contained within the element?",
Answer: "innerHTML",
Distractor1: "insertAdjacentHTML",
Distractor2: "insertElement",
Distractor3: "setHTML",
Explanation:
"The innerHTML is a property of the element that allows you to get or set the HTML markup contained within the element.",
Link: "https://youtu.be/jS4aFq5-91M?t=18781"
},
{
Question:
"In JavaScript, what is it called when you have a combination of a function and its lexical environment?",
Answer: "Closure",
Distractor1: "Debouncing",
Distractor2: "Throttling",
Distractor3: "Scope Chaining",
Explanation:
"Closures are special types of functions where the inner function will have access to variables in the outer function's scope.",
Link: "https://www.freecodecamp.org/news/a-basic-guide-to-closures-in-javascript-9fc8b7e3463e"
},
{
Question:
"In JavaScript, what does a unary plus operator attempt to convert its operand to?",
Answer: "a number",
Distractor1: "a string",
Distractor2: "an array",
Distractor3: "a sum",
Explanation:
"The unary plus operator (+) attempts to convert its operand to a number.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus"
},
{
Question:
"Which Web API used with JavaScript provides information about the size and position of an element?",
Answer: ".getBoundingClientRect()",
Distractor1: ".getOwnPropertyDescriptors()",
Distractor2: ".assign()",
Distractor3: ".entries()",
Explanation:
"The Element.getBoundingClientRect() method returns a DOMRect object providing information about the size of an element and its position relative to the viewport.",
Link: "https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect"
},
{
Question:
"In JavaScript, what is the name of the method used to remove white space from the beginning and end of a string?",
Answer: ".trim()",
Distractor1: ".substring()",
Distractor2: ".reduce()",
Distractor3: ".slice()",
Explanation:
"The .trim() method removes white space (including space, tab, etc.) from both ends of a string and returns a new string without modifying the original.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim"
},
{
Question:
"In JavaScript, which built-in method/object will return the unique values of an array?",
Answer: "Set",
Distractor1: "map()",
Distractor2: "reduce()",
Distractor3: "filter()",
Explanation:
"The Set object lets you store unique values of any type, whether primitive values or object references. Set removes duplicate entries.",
Link: "https://www.freecodecamp.org/news/lets-learn-about-set-and-its-unique-functionality-in-javascript-5654c5c03de2/"
},
{
Question:
"In JavaScript, all objects inherit a built-in property from a ___________________.",
Answer: "prototype",
Distractor1: "instance variable",
Distractor2: "node",
Distractor3: "accessor",
Explanation:
"Prototypes provide the means for JavaScript objects to inherit features from other objects.",
Link: "https://www.freecodecamp.org/news/javascript-prototype-explained-with-examples/"
},
{
Question:
"In JavaScript, every class has a special ____________ method that is used to create a new object instance of the class.",
Answer: "constructor",
Distractor1: "starter",
Distractor2: "assign",
Distractor3: "apply",
Explanation:
"Assigning 0 to the length property of the array will clear the contents of the array.",
Link: "https://www.freecodecamp.org/news/how-javascript-implements-oop/"
},
{
Question:
"In JavaScript class-based OOP, are objects and classes the same constructs?",
Answer: "No, objects and classes are two separate constructs.",
Distractor1:
"No, objects and classes are completely unrelated in JavaScript.",
Distractor2:
"Yes, objects and classes are only used in functional programming, not in JavaScript class-based OOP",
Distractor3:
"Yes, objects and classes are interchangeable and can be used interchangeably in JavaScript class-based OOP.",
Explanation:
"Classes and objects represent distinct concepts within programming. Objects are exclusively instantiated from classes.",
Link: "https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_programming"
},
{
Question:
"In JavaScript, a variable declared with the _________ keyword must be assigned an initial value.",
Answer: "const",
Distractor1: "finally",
Distractor2: "new",
Distractor3: "var",
Explanation:
"The value of a const variable must be specified when the variable is declared.",
Link: "https://www.freecodecamp.org/news/let-me-be-a-const-ant-not-a-var-iable-1be52d153462/"
},
{
Question:
"In JavaScript, a variable that has been declared but not assigned a value is known as ____________.",
Answer: "undefined",
Distractor1: "unknown",
Distractor2: "unassigned",
Distractor3: "pending",
Explanation:
"A variable that has not been assigned a value is of type undefined",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"
},
{
Question:
"In JavaScript, a variable that has been declared and assigned a value of 'no value' is ___________________",
Answer: "null",
Distractor1: "non-value",
Distractor2: "empty",
Distractor3: "unreturned",
Explanation: "In JavaScript, null represents the absence of a value.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null"
},
{
Question:
"In JavaScript, what is the index of the first element in an array?",
Answer: "0",
Distractor1: "1",
Distractor2: "first",
Distractor3: "initial",
Explanation:
"JavaScript arrays are zero-indexed. The first element of an array is located at index 0.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"
},
{
Question:
"In a JavaScript switch statement, the __________________ case executes if none of the options are true.",
Answer: "default",
Distractor1: "override",
Distractor2: "else",
Distractor3: "alert",
Explanation:
"A default clause is executed if the value of expression doesn't match any of the case clauses.",
Link: "https://www.freecodecamp.org/news/javascript-switch-case-js-switch-statement-example/"
},
{
Question:
"In JavaScript, which comparison operator is used to express strict equality?",
Answer: "===",
Distractor1: ">=",
Distractor2: "+=",
Distractor3: "<=",
Explanation:
"The strict equality operator returns true if two values have the same type and the same value. If the two compared values have different types, the result is false.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality"
},
{
Question: "Select the correct syntax for a JavaScript ES6 arrow function:",
Answer: "const variable = () => // code",
Distractor1: "const variable <=> ()()// code ",
Distractor2: "const variable === function() => {//code}",
Distractor3: "const variable =>> function(){//code}",
Explanation:
"ES6 arrow functions provide you with an alternative way to write shorter syntax compared to the traditional function expression.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"
},
{
Question:
"In JavaScript, what will be the value for the following code: null ?? 20",
Answer: "20",
Distractor1: "undefined",
Distractor2: "null",
Distractor3: "Syntax error",
Explanation:
"The nullish coalescing operator in JavaScript will return the right-hand side operand if the left-hand side operand is null or undefined.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator"
},
{
Question:
"In JavaScript, in the global execution context, 'this' refers to the ______ object whether in strict mode or not.",
Answer: "window",
Distractor1: "null",
Distractor2: "undefined",
Distractor3: "document",
Explanation:
"In the global execution context, the 'this' keyword always points to the window object",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"
},
{
Question: "In JavaScript, which queue is emptied first by an event loop?",
Answer: "Microtask queue",
Distractor1: "Callback queue (Macrotask queue)",
Distractor2: "None",
Distractor3: "Both",
Explanation:
"An event loop first empties the Microtask queue and once it is empty it starts to empty the Callback queue.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop"
},
{
Question:
"In JavaScript, which of the following is NOT in the Temporal Dead Zone(TDZ) during hoisting?",
Answer: "var",
Distractor1: "let",
Distractor2: "const",
Distractor3: "class",
Explanation:
"var is hoisted with the default value of undefined while let, const and classes are hoisted but are in the Temporal Dead Zone(TDZ) until the declaration is executed.",
Link: "https://developer.mozilla.org/en-US/docs/Glossary/Hoisting"
},
{
Question:
"In JavaScript, which of the following expressions will return true?",
Answer: "null >= 0",
Distractor1: "null == 0",
Distractor2: "null === 0",
Distractor3: "null > 0",
Explanation:
"null >= 0 and null <= 0 will both result in true because these operators will convert null to 0. With the == operator, null only equals undefined.",
Link: "https://262.ecma-international.org/5.1/#sec-11.8.5"
},
{
Question:
"In JavaScript, which of the following is a commonly used web API?",
Answer: "console",
Distractor1: "Array",
Distractor2: "Object",
Distractor3: "let, var, const",
Explanation:
"console is part of a web API which is provided by browsers and Node.js.",
Link: "https://developer.mozilla.org/en-US/docs/Web/API/console"
},
{
Question:
"In JavaScript, which of the following methods returns a function?",
Answer: "bind",
Distractor1: "apply",
Distractor2: "call",
Distractor3: "None of given",
Explanation:
"The bind function returns a new function with given arguments as the new function's 'this' keyword.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind"
},
{
Question:
"In JavaScript, which of the following methods returns the day of the month for the specified date according to local time?",
Answer: "getDate()",
Distractor1: "getTheDate()",
Distractor2: "getDay()",
Distractor3: "getFullYear()",
Explanation:
"The getDate() method returns the day of the month for the specified date according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate"
},
{
Question:
"In JavaScript, which of the following methods returns the day of the week for the specified date according to local time?",
Answer: "getDay()",
Distractor1: "getDate()",
Distractor2: "getTheSpecificDay()",
Distractor3: "getFullYear()",
Explanation:
"The getDay() method returns the day of the week for the specified date according to local time, where 0 represents Sunday. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay"
},
{
Question:
"In JavaScript, which of the following methods returns the year of the specified date according to local time?",
Answer: "getFullYear()",
Distractor1: "getDate()",
Distractor2: "listTheYear()",
Distractor3: "getMyFullYearNow()",
Explanation:
"The getFullYear() method returns the year of the specified date according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear"
},
{
Question:
"In JavaScript, which of the following methods returns the day of the hour for the specified date, according to local time?",
Answer: "getHours()",
Distractor1: "getMyHour()",
Distractor2: "getMilliseconds()",
Distractor3: "getHour()",
Explanation:
"The getHours() method returns the hour for the specified date, according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours"
},
{
Question:
"In JavaScript, which of the following methods returns the milliseconds in the specified date according to local time?",
Answer: "getMilliseconds()",
Distractor1: "getMillisec()",
Distractor2: "getTheMillisecondsNow()",
Distractor3: "getMinutes()",
Explanation:
"The getMilliseconds() method returns the milliseconds in the specified date according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds"
},
{
Question:
"In JavaScript, which of the following methods returns the minutes in the specified date according to local time?",
Answer: "getMinutes()",
Distractor1: "getMin()",
Distractor2: "getMilliseconds()",
Distractor3: "getTheMinutes()",
Explanation:
"The getMinutes() method returns the minutes in the specified date according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes"
},
{
Question:
"In JavaScript, which of the following methods returns the month in the specified date according to local time, as a zero-based value?",
Answer: "getMonth()",
Distractor1: "getTheMonth()",
Distractor2: "getSeconds()",
Distractor3: "getTime()",
Explanation:
"The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year). ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth"
},
{
Question:
"In JavaScript, which of the following methods returns the seconds in the specified date according to local time?",
Answer: "getSeconds()",
Distractor1: "getSec()",
Distractor2: "getTheSeconds()",
Distractor3: "getTime()",
Explanation:
"The getSeconds() method returns the seconds in the specified date according to local time. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds"
},
{
Question:
"In JavaScript, which of the following methods returns the number of milliseconds since the Unix Epoch?",
Answer: "getTime()",
Distractor1: "getMilliseconds()",
Distractor2: "getSeconds()",
Distractor3: "getTheTime()",
Explanation:
"The getTime() method returns the number of milliseconds since the Unix Epoch. ",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime"
},
{
Question:
"In JavaScript, which method returns an HTMLCollection object that consists of all of the elements that have the same class name?",
Answer: "getElementsByClassName()",
Distractor1: "querySelector()",
Distractor2: "getElementsByName()",
Distractor3: "getElementsByTagName()",
Explanation:
"The getElementsByClassName method returns an object containing all of the child elements with that given class name.",
Link: "https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName"
},
{
Question: "In JavaScript, which operator is used to concatenate strings?",
Answer: "+",
Distractor1: "*",
Distractor2: "&",
Distractor3: "#",
Explanation:
"The addition operator (+) produces the sum of numeric operands or string concatenation.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition"
},
{
Question: "What are the two basic groups of data types in JavaScript?",
Answer: "Primitive and Reference types",
Distractor1: "Enumerated and Object types",
Distractor2: "Primitive and Floating types",
Distractor3: "Character and Number types",
Explanation:
"Primitive and Reference types are the two basic groups of data types in JavaScript.",
Link: "https://www.freecodecamp.org/news/primitive-vs-reference-data-types-in-javascript"
},
{
Question:
"In JavaScript, what method is used to arrange array values into alphabetical and/or ascending order?",
Answer: "sort()",
Distractor1: "shift()",
Distractor2: "unshift()",
Distractor3: "from()",
Explanation:
"The sort() method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"
},
{
Question:
"In JavaScript, what method is used to arrange array values into descending order?",
Answer: "reverse()",
Distractor1: "from()",
Distractor2: "unshift()",
Distractor3: "join()",
Explanation:
"The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse"
},
{
Question:
"In JavaScript, the ____________ method returns the index position of the first occurrence of a value in a string.",
Answer: "indexOf()",
Distractor1: "getPosition()",
Distractor2: "valueOf()",
Distractor3: "charAt(0)",
Explanation:
"The indexOf() method returns the first index of the specified value in a string and will return -1 if it is not present.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf"
},
{
Question:
"In JavaScript, which of the following is the default separator in the join() method?",
Answer: "comma (',')",
Distractor1: "space (' ')",
Distractor2: "empty string ('')",
Distractor3: "full-stop ('.')",
Explanation:
"If a separator is omitted, the array elements are separated with a comma (',').",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"
},
{
Question:
"In JavaScript, which method boils an array down to a single value?",
Answer: "reduce()",
Distractor1: "map()",
Distractor2: "filter()",
Distractor3: "forEach()",
Explanation:
"The reduce() method iterates over the entire array and returns the value that results from running the “reducer” callback function to completion. The returned result is a single value.",
Link: "https://www.freecodecamp.org/news/the-ultimate-guide-to-javascript-array-methods-reduce/"
},
{
Question:
"In JavaScript, which method creates a new array and returns all of the items which pass the condition specified in the callback?",
Answer: "filter()",
Distractor1: "split()",
Distractor2: "concat()",
Distractor3: "flat()",
Explanation:
"The filter() method creates a new array and returns all of the items which pass the condition specified in the callback.",
Link: "https://www.freecodecamp.org/news/javascript-array-filter-tutorial-how-to-iterate-through-elements-in-an-array/"
},
{
Question:
"In JavaScript, which method iterates over the elements of an array and creates a new array based on the results of the function specified within said method?",
Answer: "map()",
Distractor1: "reverse()",
Distractor2: "split()",
Distractor3: "concat()",
Explanation:
"The map() method creates a new array filled with the results of calling a function (provided within the method) on every element in the array that calls the method.",
Link: "https://www.freecodecamp.org/news/array-map-tutorial/"
},
{
Question: "What kind of function accepts another function as an argument?",
Answer: "Higher order",
Distractor1: "Arrow function",
Distractor2: "Anonymous function",
Distractor3: "Named function",
Explanation:
"A Higher Order Function is any function that returns a function when executed, takes a function as one or more of its arguments, or both.",
Link: "https://www.freecodecamp.org/news/higher-order-functions-in-javascript-d9101f9cf528/"
},
{
Question:
"In JavaScript, which pair of symbols can be used in place of quotes to define a string?",
Answer: "Template literals : ``",
Distractor1: "Square brackets: []",
Distractor2: "Curly braces: {}",
Distractor3: "Angle brackets: <>",
Explanation:
"Template literals are literals delimited with backticks (`), allowing embedded expressions called substitutions. Untagged template literals result in strings, which makes them useful for string interpolation (and multiline strings, since unescaped newlines are allowed).",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"
},
{
Question:
"In JavaScript, what is the name of the method that is used to convert a string into an array?",
Answer: "split()",
Distractor1: "slice()",
Distractor2: "trim()",
Distractor3: "concat()",
Explanation:
"The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"
},
{
Question:
"In JavaScript, what method removes the first element of an array and returns it?",
Answer: ".shift()",
Distractor1: ".push()",
Distractor2: ".pop()",
Distractor3: ".unshift()",
Explanation:
"The .shift() method removes the first element of an array and returns it. ",
Link: "https://www.freecodecamp.org/news/the-javascript-array-handbook/"
},
{
Question: "In JavaScript, what is the value of x ? let x = undefined || 1;",
Answer: "1",
Distractor1: "2",
Distractor2: "undefined",
Distractor3: "null",
Explanation:
"The value of x is 1 because undefined is a falsy value and that's why 1 is assigned to the variable x.",
Link: "https://www.freecodecamp.org/news/javascript-logical-operators/"
},
{
Question: "In JavaScript, how do you create a promise inside a function?",
Answer: "return new Promise((resolve, reject) => {})",
Distractor1: "return new Promise(resolve, reject)",
Distractor2: "return new Promise((resolve, reject))",
Distractor3: "return Promise((reject, resolve))",
Explanation:
"You can use a promise inside a function with the following syntax: return new Promise((resolve, reject) => {})",
Link: "https://www.freecodecamp.org/news/javascript-promises-explained/"
},
{
Question:
"In JavaScript, what is the correct syntax to check if two variables are strictly equal?",
Answer: "if(A === B)",
Distractor1: "if(A == B)",
Distractor2: "if(A = B)",
Distractor3: "if(A.equals(B))",
Explanation:
"The triple equals operator (===) will check for strict equality because it checks for the same data type and value.",
Link: "https://www.freecodecamp.org/news/javascript-promises-explained/"
},
{
Question:
"In JavaScript, what method adds an element to the end of an array?",
Answer: ".push()",
Distractor1: ".pop()",
Distractor2: ".shift()",
Distractor3: ".unshift()",
Explanation: "The .push() method adds an element to the end of the array.",
Link: "https://www.freecodecamp.org/news/the-javascript-array-handbook/"
},
{
Question: "What does JSON stand for?",
Answer: "JavaScript Object Notation",
Distractor1: "Jupiter Script Object Notation",
Distractor2: "Jabber Script Object Notation",
Distractor3: "Jargon Script Object Notation",
Explanation:
"JSON stands for JavaScript Object Notation which is a text-based format to store and exchange data.",
Link: "https://www.freecodecamp.org/news/what-is-json-a-json-file-example/"
},
{
Question:
"In JavaScript, what is the name of the technique used to extract an object's values into new variables?",
Answer: "Object destructuring",
Distractor1: "Array destructuring",
Distractor2: "Hoisting",
Distractor3: "typeof",
Explanation:
"Object destructuring is used to extract an object's values into new variables.",
Link: "https://www.freecodecamp.org/news/array-vs-object-destructuring-in-javascript/"
},
{
Question:
"In JavaScript, which one of these methods modifies an array in place?",
Answer: ".splice()",
Distractor1: ".slice()",
Distractor2: ".filter()",
Distractor3: ".join()",
Explanation:
"The .splice() method modifies an array in place and it can be used to remove or add elements to an array.",
Link: "https://www.freecodecamp.org/news/javascript-array-slice-vs-splice-whats-the-difference/"
},
{
Question:
"Which of the following tools are the most convenient for running tasks in a NodeJS environment?",
Answer: "npm scripts",
Distractor1: "gulp",
Distractor2: "grunt",
Distractor3: "Makefile",
Explanation:
"Npm scripts allow command line tools to be called directly without relying on external plugins.",
Link: "https://www.freecodecamp.org/news/why-i-left-gulp-and-grunt-for-npm-scripts-3d6853dd22b8/"
},
{
Question: "In JavaScript, how can you convert a string to an integer?",
Answer: "parseInt()",
Distractor1: "parseString()",
Distractor2: "parseInteger()",
Distractor3: "parseSrt()",
Explanation:
"The parseInt() function converts the value passed as an argument to an integer.",
Link: "https://www.freecodecamp.org/news/convert-string-to-number-javascript/"
},
{
Question: "In JavaScript, how do you write a multiline comment?",
Answer: "/* */",
Distractor1: "//",
Distractor2: "<!-- -->",
Distractor3: "** **",
Explanation: "In JavaScript, we use /* */ to write a multiline comment.",
Link: "https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-comment-your-javascript-code/16783"
},
{
Question: "In JavaScript, what is the logical AND operator?",
Answer: "&&",
Distractor1: "||",
Distractor2: "!",
Distractor3: "**",
Explanation: "&& is the logical AND operator in JavaScript.",
Link: "https://www.freecodecamp.org/news/javascript-logical-operators/"
},
{
Question:
"In JavaScript, which one of these types of loops will always run at least once?",
Answer: "Do... While Loop",
Distractor1: "While Loop",
Distractor2: "For Loop",
Distractor3: "for each",
Explanation:
"The sequence of statements in a do..while loop runs at least once because the condition is evaluated after running the statements. ",
Link: "https://www.freecodecamp.org/news/javascript-loops-explained-for-loop-for/"
},
{
Question: "Which one is NOT a JavaScript library?",
Answer: "C#",
Distractor1: "React",
Distractor2: "D3",
Distractor3: "Moment",
Explanation:
"There are many popular JavaScript libraries including React, D3 and Moment.",
Link: "https://www.freecodecamp.org/news/10-javascript-libraries-you-should-try/"
},
{
Question:
"In JavaScript, what is the name of the method used to add new elements to the DOM tree?",
Answer: "document.createElement()",
Distractor1: "Callback function",
Distractor2: ".querySelectorAll()",
Distractor3: ".textContent()",
Explanation:
"The document.createElement() method is used to add new elements to the DOM tree.",
Link: "https://www.freecodecamp.org/news/what-is-the-dom-document-object-model-meaning-in-javascript/"
},
{
Question:
"In JavaScript, what is the name of the property used to get the text content of a node in the DOM?",
Answer: "textContent",
Distractor1: "text-content",
Distractor2: "content",
Distractor3: "getContent",
Explanation:
"The textContent property is used to get the text content of a node in the DOM.",
Link: "https://www.freecodecamp.org/news/what-is-the-dom-document-object-model-meaning-in-javascript/"
},
{
Question:
"In JavaScript, what is the JavaScript keyword used to define a constant?",
Answer: "const",
Distractor1: "var",
Distractor2: "let",
Distractor3: "concat",
Explanation:
"The keyword const is used to define a constant in JavaScript. The value of a constant can't be changed through reassignment.",
Link: "https://www.freecodecamp.org/news/javascript-variables-beginners-guide/"
},
{
Question:
"In JavaScript, what is the name of the technique used to extract array values into new variables?",
Answer: "Array destructuring",
Distractor1: "typeof",
Distractor2: "async",
Distractor3: "Optional chaining",
Explanation:
"Array destructuring is used to extract array values into new variables.",
Link: "https://www.freecodecamp.org/news/array-vs-object-destructuring-in-javascript/"
},
{
Question:
"In JavaScript, what is the name of the method used to see if one string is found in another?",
Answer: ".includes()",
Distractor1: ".padEnd()",
Distractor2: ".slice()",
Distractor3: ".trim()",
Explanation:
"The .includes() method is used to check if one string is found in another.",
Link: "https://www.freecodecamp.org/news/javascript-string-contains-how-to-use-js-includes/"
},
{
Question:
"In JavaScript, what is the name for variables that are accessible throughout the program?",
Answer: "Global variables",
Distractor1: "Const variables",
Distractor2: "Local variables",
Distractor3: "No variable is accessible throughout in JavaScript",
Explanation:
"Global variables are declared and made accessible throughout the entire JavaScript program.",
Link: "https://www.freecodecamp.org/news/global-variables-in-javascript-explained/"
},
{
Question: "In JavaScript, what keyword is used to define a function?",
Answer: "function",
Distractor1: "def",
Distractor2: "func",
Distractor3: "fct",
Explanation:
"The function keyword is used to define a function in JavaScript.",
Link: "https://www.freecodecamp.org/news/what-is-a-function-javascript-function-examples/"
},
{
Question:
"In JavaScript, what is the name of the method that extracts a portion of an array and returns a new array?",
Answer: ".slice()",
Distractor1: ".splice()",
Distractor2: ".pop()",
Distractor3: ".sort()",
Explanation:
"The .slice() method extracts a portion of an array and returns a new array.",
Link: "https://www.freecodecamp.org/news/javascript-array-slice-vs-splice-whats-the-difference/"
},
{
Question:
"In JavaScript, what is the name of the method used to select elements in an HTML document by referencing the id name?",
Answer: ".getElementById()",
Distractor1: ".getElementByClass()",
Distractor2: ".getId()",
Distractor3: ".getElementByTagName()",
Explanation:
"The .getElementById() method is used to select elements in the HTML document by referencing the id name.",
Link: "https://www.freecodecamp.org/news/what-is-the-dom-document-object-model-meaning-in-javascript/"
},
{
Question: "In HTML, what are <script> tags?",
Answer: "they're used for client side JavaScript code",
Distractor1: "used for server side JavaScript code",
Distractor2: "used to link SQL databases",
Distractor3: "used to link noSQL databases",
Explanation: "The script tag is used for client side JavaScript code.",
Link: "https://www.freecodecamp.org/news/basic-html5-template-boilerplate-code-example/"
},
{
Question:
"In JavaScript, which one of these operators is the equality operator?",
Answer: "==",
Distractor1: "?",
Distractor2: "!=",
Distractor3: "!==",
Explanation:
"The == operator returns true if two values are equal and false if they are not equal. It converts the values to a common type before doing the comparison.",
Link: "https://www.freecodecamp.org/news/javascript-triple-equals-sign-vs-double-equals-sign-comparison-operators-explained-with-examples/"
},
{
Question:
"In JavaScript, what string method returns the character at the specified index?",
Answer: ".charAt()",
Distractor1: ".getChar()",
Distractor2: ".char()",
Distractor3: ".character()",
Explanation:
"The .charAt() method returns the character at the specified index in JavaScript.",
Link: "https://devdocs.io/javascript/global_objects/string/charat"
},
{
Question: "What is the main purpose of JavaScript in a website?",
Answer: "Functionality",
Distractor1: "Structure",
Distractor2: "Style",
Distractor3: "Sound",
Explanation:
"JavaScript is used to create interactive and dynamic websites.",
Link: "https://www.freecodecamp.org/news/what-is-javascript-javascript-code-explained-in-plain-english/"
},
{
Question: "Are semicolons strictly required in JavaScript?",
Answer: "No",
Distractor1: "Yes",
Distractor2: "only when using the concat method",
Distractor3: "only when using the split method",
Explanation:
"JavaScript does not require strict use of semicolons because it inserts them where they are needed through a process called Automatic Semicolon Insertion.",
Link: "https://www.freecodecamp.org/news/lets-talk-about-semicolons-in-javascript-f1fe08ab4e53/#:~:text=This%20is%20all%20possible%20because%20JavaScript%20does%20not%20strictly%20require%20semicolons.&text=It's%20important%20to%20know%20the,not%20behave%20like%20you%20expect."
},
{
Question:
"In JavaScript, what value is returned by default when a function doesn't have a return statement?",
Answer: "undefined",
Distractor1: "None",
Distractor2: "concat",
Distractor3: "0",
Explanation:
"The value undefined is returned by functions that do not have a return statement.",
Link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions"
},
{
Question:
"In JavaScript, what operator takes an array and spreads it into its individual elements?",
Answer: "Spread operator",
Distractor1: "Rest operator",
Distractor2: "Division Operator",
Distractor3: "Multiplication Operator",
Explanation:
"The spread operator takes an array and spreads it into its individual elements. With this operator, we can pass the elements of an array as individual arguments to a function call.",
Link: "https://www.freecodecamp.org/news/javascript-rest-vs-spread-operators/"
},
{
Question:
"In JavaScript, what method removes the last element of an array and returns it?",
Answer: ".pop()",
Distractor1: ".push()",
Distractor2: ".shift()",
Distractor3: ".unshift()",
Explanation:
"The .pop() method removes the last element of an array and returns it.",
Link: "https://www.freecodecamp.org/news/the-javascript-array-handbook/"
},
{
Question:
"In JavaScript, which one of these variable declarations can be re declared within its scope?",
Answer: "var",