@palerock/exam-qa 1.0.6-patch15 → 1.0.6-patch17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1787 @@
1
+ {
2
+ "title": "[JS]第二章 对象-函数-类",
3
+ "category": "JS-1",
4
+ "questions": [
5
+ {
6
+ "describe": "<p>Which function should a developer use to repeatedly execute code at a fixed time interval?</p>",
7
+ "answerOptions": [
8
+ {
9
+ "describe": "<p>setInterval</p>",
10
+ "isRight": true
11
+ },
12
+ {
13
+ "describe": "<p>setTimeout</p>",
14
+ "isRight": false
15
+ },
16
+ {
17
+ "describe": "<p>setPeriod</p>",
18
+ "isRight": false
19
+ },
20
+ {
21
+ "describe": "<p>setInterim</p>",
22
+ "isRight": false
23
+ }
24
+ ],
25
+ "analysis": "<p>The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).</p><p>setTimeout execute a specified block of code once after a specified time has elapsed.</p>",
26
+ "hashCode": 1543270785
27
+ },
28
+ {
29
+ "describe": "<p>A developer creates an object where its properties should be immutable and prevent properties from being added or modified.Which method should be used to execute this business requirement?</p>",
30
+ "answerOptions": [
31
+ {
32
+ "describe": "<p>Object.seal( )</p>",
33
+ "isRight": false
34
+ },
35
+ {
36
+ "describe": "<p>Object.const( )</p>",
37
+ "isRight": false
38
+ },
39
+ {
40
+ "describe": "<p>Object.freeze( )</p>",
41
+ "isRight": true
42
+ },
43
+ {
44
+ "describe": "<p>Object.lock( )</p>",
45
+ "isRight": false
46
+ }
47
+ ],
48
+ "analysis": "<p>The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.</p><p>The Object.freeze() method freezes an object. A frozen object can no longer be changed; freezing an object prevents new properties from being added to it, existing properties from being removed, prevents changing the enumerability, configurability, or writability of existing properties, and prevents the values of existing properties from being changed. In addition, freezing an object also prevents its prototype from being changed. freeze() returns the same object that was passed in.</p>",
49
+ "hashCode": -1236958766
50
+ },
51
+ {
52
+ "describe": "<p>Given the following code:</p><p>let x= ( '15' + 10 ) * 2;</p><p>What is the value of x?</p>",
53
+ "answerOptions": [
54
+ {
55
+ "describe": "<p>50</p>",
56
+ "isRight": false
57
+ },
58
+ {
59
+ "describe": "<p>3020</p>",
60
+ "isRight": true
61
+ },
62
+ {
63
+ "describe": "<p>35</p>",
64
+ "isRight": false
65
+ },
66
+ {
67
+ "describe": "<p>1520</p>",
68
+ "isRight": false
69
+ }
70
+ ],
71
+ "analysis": "",
72
+ "hashCode": 1566378556
73
+ },
74
+ {
75
+ "describe": "<p>Refer to the code below:</p><p>01 const car = {</p><p>02 price: 100,</p><p>03 getPrice: function ( ) {</p><p>04 return this.price;</p><p>05 }</p><p>06 };</p><p>07 const customCar = Object.create(car);</p><p>08 customCar.price = 70;</p><p>09</p><p>10 delete customCar.price;</p><p>11 const result = customCar.getPrice( );</p><p>Considering the implications of line 10 along with prototype inheritance, what is the value of result after the code executes?</p>",
76
+ "answerOptions": [
77
+ {
78
+ "describe": "<p>100</p>",
79
+ "isRight": true
80
+ },
81
+ {
82
+ "describe": "<p>undefined</p>",
83
+ "isRight": false
84
+ },
85
+ {
86
+ "describe": "<p>70</p>",
87
+ "isRight": false
88
+ },
89
+ {
90
+ "describe": "<p>null</p>",
91
+ "isRight": false
92
+ }
93
+ ],
94
+ "analysis": "<p>create() The Object. create() method creates a new object, using an existing object as the prototype of the newly created object</p><p>In line 10, the price property is deleted. But in the prototype chain, therer is another price property.</p><p>{price: 70}</p><p>price: 70</p><p>__proto__:</p><p>getPrice: ƒ ( )</p><p>price: 100</p><p>__proto__: Object</p>",
95
+ "hashCode": 796642343
96
+ },
97
+ {
98
+ "describe": "<p>Refer to the code below:</p><p>01 function changeValue(obj) {</p><p>02 obj.value = obj.value / 2;</p><p>03 }</p><p>04 const objA = { value : 10};</p><p>05 const objB = objA;</p><p>06</p><p>07 changeValue(objB);</p><p>08 const result = objA.value;</p><p>What is the value of result after the code executes?</p>",
99
+ "answerOptions": [
100
+ {
101
+ "describe": "<p>NaN</p>",
102
+ "isRight": false
103
+ },
104
+ {
105
+ "describe": "<p>10</p>",
106
+ "isRight": false
107
+ },
108
+ {
109
+ "describe": "<p>undefined</p>",
110
+ "isRight": false
111
+ },
112
+ {
113
+ "describe": "<p>5</p>",
114
+ "isRight": true
115
+ }
116
+ ],
117
+ "analysis": "<p>objA and objB point to the same address in the stack. So they are same object. In line 7, the method changes the object.value, so in line8, the object.value = 5</p>",
118
+ "hashCode": -1558274561
119
+ },
120
+ {
121
+ "describe": "<p>Which three options show valid methods for creating a fat arrow function? Choose 3 answer</p>",
122
+ "answerOptions": [
123
+ {
124
+ "describe": "<p>[ ] => { console.log( 'executed' ); }</p>",
125
+ "isRight": false
126
+ },
127
+ {
128
+ "describe": "<p>( ) => { console.log( 'executed' ); }</p>",
129
+ "isRight": true
130
+ },
131
+ {
132
+ "describe": "<p>( x, y, z ) => { console.log( 'executed' ); }</p>",
133
+ "isRight": true
134
+ },
135
+ {
136
+ "describe": "<p>x, y, z => { console.log( 'executed' ); }</p>",
137
+ "isRight": false
138
+ },
139
+ {
140
+ "describe": "<p>x => { console.log( 'executed' ); }</p>",
141
+ "isRight": true
142
+ }
143
+ ],
144
+ "analysis": "<p>If no parameter, the () should not be omitted, if more than one parameter, the () should not be omitted, if only one parameter, the () can be omitted</p>",
145
+ "hashCode": -710754372
146
+ },
147
+ {
148
+ "describe": "<p>Refer to the following code block:</p><p>01 class Student {</p><p>02 constructor(name) {</p><p>03 this.name = name;</p><p>04 }</p><p>05</p><p>06 takeTest() {</p><p>07 console.log(`${this.name} got 70% on test.`);</p><p>08 }</p><p>09 }</p><p>10</p><p>11 class BetterStudent extends Student {</p><p>12 constructor(name) {</p><p>13 super(name);</p><p>14 this.name = 'Better student ' + name;</p><p>15 }</p><p>16 takeTest() {</p><p>17 console.log(`${this.name} got 100% on the test.`);</p><p>18 }</p><p>19 }</p><p>20</p><p>21 let student = new BetterStudent('Jackie');</p><p>22 student.takeTest();</p><p>What is the console output?</p>",
149
+ "answerOptions": [
150
+ {
151
+ "describe": "<p>> Jackie got 70% on test.</p>",
152
+ "isRight": false
153
+ },
154
+ {
155
+ "describe": "<p>> Better student Jackie got 100% on test.</p>",
156
+ "isRight": true
157
+ },
158
+ {
159
+ "describe": "<p>> Better student Jackie got 70% on test.</p>",
160
+ "isRight": false
161
+ },
162
+ {
163
+ "describe": "<p>> Uncaught ReferenceError</p>",
164
+ "isRight": false
165
+ }
166
+ ],
167
+ "analysis": "<p>line 13 super(name) will call line 3. Then in line 13, this.name will update the name.</p><p>the takeTest() method is line 16 will be called. Only if in current class there is no such a method, js will look at the parent class.</p>",
168
+ "hashCode": 516074974
169
+ },
170
+ {
171
+ "describe": "<p>A developer is required to write a function that calculates the sum of elements in an array but is getting undefined every time the code is executed. The developer needs to find what is missing in the code below.</p><p>01 const sumFunction = arr =>{</p><p>02 return arr.reduce((result, current) =>{</p><p>03 //</p><p>04 result += current;</p><p>05 //</p><p>06 },10);</p><p>07 };</p><p>Which option makes the code work as expected?</p>",
172
+ "answerOptions": [
173
+ {
174
+ "describe": "<p>Replace line 02 with return arr.map((result, current) =>{</p>",
175
+ "isRight": false
176
+ },
177
+ {
178
+ "describe": "<p>Replace line 05 with return result;</p>",
179
+ "isRight": true
180
+ },
181
+ {
182
+ "describe": "<p>Replace line 04 with result = result + current;</p>",
183
+ "isRight": false
184
+ },
185
+ {
186
+ "describe": "<p>Replace line 03 with if(arr.length == 0) {return 0;}</p>",
187
+ "isRight": false
188
+ }
189
+ ],
190
+ "analysis": "<p>JS Array Reduce method: https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/array/reduce</p><p>map method will return an array by executing the callback method for each of the element in the original array</p><p>result +=current equals to result = result + current</p>",
191
+ "hashCode": 2083887382
192
+ },
193
+ {
194
+ "describe": "<p>Given the code below:</p><p>01 function myFunction() {</p><p>02 a = 5;</p><p>03 var b = 1;</p><p>04 }</p><p>05</p><p>06 myFunction();</p><p>07</p><p>08 console.log(a);</p><p>09 console.log(b);</p><p>What is the expected output?</p>",
195
+ "answerOptions": [
196
+ {
197
+ "describe": "<p>Line 08 outputs the variable, but line 09 throws an error.</p>",
198
+ "isRight": false
199
+ },
200
+ {
201
+ "describe": "<p>Both lines 08 and 09 are executed, and the variables are outputted.</p>",
202
+ "isRight": false
203
+ },
204
+ {
205
+ "describe": "<p>Line 08 throws an error, therefore line 09 is never executed.</p>",
206
+ "isRight": false
207
+ },
208
+ {
209
+ "describe": "<p>Both lines 08 and 09 are executed, but the values outputted are undefined.</p>",
210
+ "isRight": true
211
+ }
212
+ ],
213
+ "analysis": "",
214
+ "hashCode": -399108392
215
+ },
216
+ {
217
+ "describe": "<p>Refer to the following code:</p><p>01 function Tiger() {</p><p>02 this.type = 'Cat';</p><p>03 this.size = 'large';</p><p>04 }</p><p>05</p><p>06 let tony = new Tiger();</p><p>07 tony.roar = () => {</p><p>08 console.log('They\\'re great!');</p><p>09 };</p><p>10</p><p>11 function Lion() {</p><p>12 this.type = 'Cat';</p><p>13 this.size = 'large';</p><p>14 }</p><p>15</p><p>16 let leo = new Lion();</p><p>17 // Insert code here</p><p>18 leo.roar();</p><p>Which two statements could be inserted at line 17 to enable the function call on line 18? Choose 2 answers</p><p></p>",
218
+ "answerOptions": [
219
+ {
220
+ "describe": "<p>Object.assign(leo, tony);</p>",
221
+ "isRight": true
222
+ },
223
+ {
224
+ "describe": "<p>Object.assign(leo, Tiger);</p>",
225
+ "isRight": false
226
+ },
227
+ {
228
+ "describe": "<p>leo.prototype.roar = () => {console.log('They\\'re pretty good!');};</p>",
229
+ "isRight": false
230
+ },
231
+ {
232
+ "describe": "<p>leo.roar = () => {console.log('They\\'re pretty good!');};</p>",
233
+ "isRight": true
234
+ }
235
+ ],
236
+ "analysis": "<p>The Object. assign() method only copies enumerable and own properties from a source object to a target object. But Tiger is a function.</p><p>The JavaScript prototype property allows you to add new properties to object constructors. Should be Lion.prototype.roar.</p>",
237
+ "hashCode": 1036209143
238
+ },
239
+ {
240
+ "describe": "<p>Refer to the code declarations below:</p><p>let str1 = 'Java';</p><p>let str2 = 'Script';</p><p>Which three expressions return the string JavaScript? Choose 3 answers</p>",
241
+ "answerOptions": [
242
+ {
243
+ "describe": "<p>str1.join(str2);</p>",
244
+ "isRight": false
245
+ },
246
+ {
247
+ "describe": "<p>str1.concat(str2);</p>",
248
+ "isRight": true
249
+ },
250
+ {
251
+ "describe": "<p>`${str1}${str2}`;</p>",
252
+ "isRight": true
253
+ },
254
+ {
255
+ "describe": "<p>concat(str1, str2);</p>",
256
+ "isRight": false
257
+ },
258
+ {
259
+ "describe": "<p>str1 + str2;</p>",
260
+ "isRight": true
261
+ }
262
+ ],
263
+ "analysis": "<p>No join method on String: join</p><p>Should be str1.concat(str2);</p>",
264
+ "hashCode": -656405866
265
+ },
266
+ {
267
+ "describe": "<p></p>",
268
+ "answerOptions": [
269
+ {
270
+ "describe": "<p>developer has two ways to write a function:</p><p>Option A:</p><p>01 function Monster( ) {</p><p>02 this.growl = ( ) => {</p><p>03 console.log(\"Grr!\");</p><p>04 }</p><p>05 }</p><p>Option B:</p><p>01 function Monster( ) { };</p><p>02 Monster.prototype.growl = ( ) => {</p><p>03 console.log(\"Grr!\");</p><p>04 }</p><p>After deciding on an option, the developer creates 1000 monster objects.</p><p>How many growl methods are created with Option A and Option</p>",
271
+ "isRight": false
272
+ },
273
+ {
274
+ "describe": "<p>?</p><p>A 1000 growl methods are created regardless of which option is used.</p><p>B 1 growl method is created regardless of which option is used.</p>",
275
+ "isRight": false
276
+ },
277
+ {
278
+ "describe": "<p>1000 growl methods are created for Option A.1 growl method is created for Option B.</p>",
279
+ "isRight": true
280
+ },
281
+ {
282
+ "describe": "<p>1 growl method is created for Option A. 1000 growl methods are created for Option B.</p>",
283
+ "isRight": false
284
+ }
285
+ ],
286
+ "analysis": "<p>with prototype, the growl function will be existing in Monster's prototype chain. All instances initialized from Monster will share the same function reference.</p><p>In Option A, however, each instance of Monster will have their own growl function.</p>",
287
+ "hashCode": 0
288
+ },
289
+ {
290
+ "describe": "<p>Refer to the code below:</p><p>01 let first = 'Who';</p><p>02 let second = 'What';</p><p>03 try {</p><p>04 try {</p><p>05 throw new Error('Sad trombone');</p><p>06 } catch (err) {</p><p>07 first = 'Why' ;</p><p>08 throw err;</p><p>09 } finally {</p><p>10 second = 'When' ;</p><p>11 }</p><p>12 } catch (err) {</p><p>13 second = 'Where' ;</p><p>14 }</p><p>What are the values for first and second once the code executes?</p><p></p>",
291
+ "answerOptions": [
292
+ {
293
+ "describe": "<p>First is Who and second is When.</p>",
294
+ "isRight": false
295
+ },
296
+ {
297
+ "describe": "<p>First is Why and second is Where.</p>",
298
+ "isRight": true
299
+ },
300
+ {
301
+ "describe": "<p>first is Who and second is Where.</p>",
302
+ "isRight": false
303
+ },
304
+ {
305
+ "describe": "<p>first is Why and second is When.</p>",
306
+ "isRight": false
307
+ }
308
+ ],
309
+ "analysis": "",
310
+ "hashCode": 73813081
311
+ },
312
+ {
313
+ "describe": "<p>A developer wants to create an object from a function in the browser using the code below.</p><p>01 function Monster( ){ this.name = 'hello' };</p><p>02 const m = Monster( );</p><p>What happens due to the lack of the new keyword on line 02?</p><p></p>",
314
+ "answerOptions": [
315
+ {
316
+ "describe": "<p>window.name is assigned to 'hello' and the variable m remains undefined.</p>",
317
+ "isRight": true
318
+ },
319
+ {
320
+ "describe": "<p>The m variable is assigned the correct object but this.name remains undefined.</p>",
321
+ "isRight": false
322
+ },
323
+ {
324
+ "describe": "<p>The m variable is assigned the correct object.</p>",
325
+ "isRight": false
326
+ },
327
+ {
328
+ "describe": "<p>window.m is assigned the correct object.</p>",
329
+ "isRight": false
330
+ }
331
+ ],
332
+ "analysis": "<p>without new, it is like calling Monster() function, and at this time, this points to windows object. So it is like assigning a name attribtue to the window object</p>",
333
+ "hashCode": 1929130382
334
+ },
335
+ {
336
+ "describe": "<p>Refer to the code below:</p><p>01 let o = {</p><p>02 get js( ) {</p><p>03 let city1 = String('st. Louis');</p><p>04 let city2 = String('New York');</p><p>05</p><p>06 return {</p><p>07 firstCity: city1.toLowerCase( ) ,</p><p>08 secondCity: city2.toLowerCase( ) ,</p><p>09 }</p><p>10 }</p><p>11 }</p><p>What value can a developer expect when referencing o.js.secondCity?</p><p></p>",
337
+ "answerOptions": [
338
+ {
339
+ "describe": "<p>'new york'</p>",
340
+ "isRight": true
341
+ },
342
+ {
343
+ "describe": "<p>undefined</p>",
344
+ "isRight": false
345
+ },
346
+ {
347
+ "describe": "<p>'New York'</p>",
348
+ "isRight": false
349
+ },
350
+ {
351
+ "describe": "<p>An error</p>",
352
+ "isRight": false
353
+ }
354
+ ],
355
+ "analysis": "",
356
+ "hashCode": 458433156
357
+ },
358
+ {
359
+ "describe": "<p>Refer to the code below:</p><p>01 const objBook = {</p><p>02 title: 'JavaScript' ,</p><p>03 };</p><p>04 Object.preventExtensions (objBook) ;</p><p>05 const newObjBook = objBook;</p><p>06 newObjBook.author = 'Robert' ;</p><p>What are the values of objBook and newObjBook respectively?</p><p></p>",
360
+ "answerOptions": [
361
+ {
362
+ "describe": "<p>{ title: \"JavaScript\" }</p><p>{ title: \"JavaScript\" }</p>",
363
+ "isRight": true
364
+ },
365
+ {
366
+ "describe": "<p>{ author: \"Robert\", title: \"JavaScript\" }</p><p>{ author: \"Robert\", title: \"JavaScript\" }</p>",
367
+ "isRight": false
368
+ },
369
+ {
370
+ "describe": "<p>{ author: \"Robert\", title: \"JavaScript\" }</p><p>undefined</p>",
371
+ "isRight": false
372
+ },
373
+ {
374
+ "describe": "<p>{ author: \"Robert\" }</p><p>{ author: \"Robert\", title: \"JavaScript\" }</p>",
375
+ "isRight": false
376
+ }
377
+ ],
378
+ "analysis": "<p>The Object.preventExtensions() method prevents new properties from ever being added to an object</p>",
379
+ "hashCode": 1760512837
380
+ },
381
+ {
382
+ "describe": "<p>What are two unique features of functions defined with a fat arrow as compared to normal function definition? Choose 2 answers</p><p></p>",
383
+ "answerOptions": [
384
+ {
385
+ "describe": "<p>The function generates its own this making it useful for separating the function's scope from its enclosing scope.</p>",
386
+ "isRight": false
387
+ },
388
+ {
389
+ "describe": "<p>The function uses the this from the enclosing scope.</p>",
390
+ "isRight": true
391
+ },
392
+ {
393
+ "describe": "<p>If the function has a single expression in the function body, the expression will be evaluated and implicitly returned.</p>",
394
+ "isRight": true
395
+ },
396
+ {
397
+ "describe": "<p>The function receives an argument that is always in scope, called parentThis, which is the enclosing lexical scope.</p>",
398
+ "isRight": false
399
+ }
400
+ ],
401
+ "analysis": "",
402
+ "hashCode": 1172379641
403
+ },
404
+ {
405
+ "describe": "<p>Refer to the code below:</p><p>01 const myFunction = arr => {</p><p>02 return arr. reduce((result, current) => {</p><p>03 return result + current;</p><p>04 }, 10);</p><p>05 }</p><p>What is the output if this function when called with an empty array?</p><p></p>",
406
+ "answerOptions": [
407
+ {
408
+ "describe": "<p>Returns 10</p>",
409
+ "isRight": true
410
+ },
411
+ {
412
+ "describe": "<p>Returns 0</p>",
413
+ "isRight": false
414
+ },
415
+ {
416
+ "describe": "<p>Throws an error</p>",
417
+ "isRight": false
418
+ },
419
+ {
420
+ "describe": "<p>Returns NaN</p>",
421
+ "isRight": false
422
+ }
423
+ ],
424
+ "analysis": "<p>check array reduce method</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce</p>",
425
+ "hashCode": -224928759
426
+ },
427
+ {
428
+ "describe": "<p>Refer to the code:</p><p>01 function Animal(size, type) {</p><p>02 this.type = type || 'Animal' ;</p><p>03 this.canTalk = false ;</p><p>04 }</p><p>05</p><p>06 Animal.prototype.speak = function( ) {</p><p>07 if (this.canTalk) {</p><p>08 console.log(\"It spoke!\") ;</p><p>09 }</p><p>10 } ;</p><p>11</p><p>12 let Pet = function(size, type ,name, owner) {</p><p>13 Animal.call(this, size, type);</p><p>14 this.size = size;</p><p>15 this.name = name;</p><p>16 this.owner = owner;</p><p>17 }</p><p>18</p><p>19 Pet.prototype = Object.create(Animal.prototype);</p><p>20 let pet1 = new Pet( );</p><p>Given the code above, which three properties are set for pet1? Choose 3 answers</p>",
429
+ "answerOptions": [
430
+ {
431
+ "describe": "<p>speak</p>",
432
+ "isRight": true
433
+ },
434
+ {
435
+ "describe": "<p>canTalk</p>",
436
+ "isRight": true
437
+ },
438
+ {
439
+ "describe": "<p>owner</p>",
440
+ "isRight": false
441
+ },
442
+ {
443
+ "describe": "<p>name</p>",
444
+ "isRight": false
445
+ },
446
+ {
447
+ "describe": "<p>type</p>",
448
+ "isRight": true
449
+ }
450
+ ],
451
+ "analysis": "<p>speak is a function in pet1's prototype chain</p><p>size, name, owner of pet1 is undefined</p>",
452
+ "hashCode": 1047844977
453
+ },
454
+ {
455
+ "describe": "<p>Given the code below:</p><p>01 function Person (name, email) {</p><p>02 this.name = name ;</p><p>03 this.email = email ;</p><p>04 }</p><p>05</p><p>06 const john = new Person('John', 'john@email.com');</p><p>07 const jane = new Person('Jane', 'jane@email.com');</p><p>08 const emily = new Person(' Emily', 'emily@email.com');</p><p>09</p><p>10 let usersList = [john, jane, emily];</p><p>Which method can be used to provide a visual representation of the list of users and to allow sorting by the name or email attribute?</p><p></p>",
456
+ "answerOptions": [
457
+ {
458
+ "describe": "<p>console.group (usersList) ;</p>",
459
+ "isRight": false
460
+ },
461
+ {
462
+ "describe": "<p>console.table (usersList) ;</p>",
463
+ "isRight": true
464
+ },
465
+ {
466
+ "describe": "<p>console.groupCollapsed(usersList) ;</p>",
467
+ "isRight": false
468
+ },
469
+ {
470
+ "describe": "<p>console.info(usersList);</p>",
471
+ "isRight": false
472
+ }
473
+ ],
474
+ "analysis": "<p>This function takes one mandatory argument data, which must be an array or an object, and one additional optional parameter columns.</p><p>It logs data as a table. Each element in the array (or enumerable property if data is an object) will be a row in the table.</p><p>check console.table();</p><p>https://developer.mozilla.org/en-US/docs/Web/API/Console/table</p>",
475
+ "hashCode": -377381709
476
+ },
477
+ {
478
+ "describe": "<p>A developer wants to use a module named universalContainersLib and then call functions from it.</p><p>How should a developer import every function from the module and then call the functions foo and bar?</p><p></p>",
479
+ "answerOptions": [
480
+ {
481
+ "describe": "<p>import * as lib from '/path/universalContainersLib.js' ;</p><p>lib.foo( ) ;</p><p>lib.bar( ) ;</p>",
482
+ "isRight": true
483
+ },
484
+ {
485
+ "describe": "<p>import all from '/path/universalContainersLib.js' ;</p><p>universalContainersLib. foo( ) ;</p><p>universalContainersLib.bar( ) ;</p>",
486
+ "isRight": false
487
+ },
488
+ {
489
+ "describe": "<p>import * from 'path/universalContainersLib.js' ;</p><p>universalContainersLib. foo( ) ;</p><p>universalContainersLib.bar( ) ;</p>",
490
+ "isRight": false
491
+ },
492
+ {
493
+ "describe": "<p>import {foo,bar} from 'path/universalContainersLib.js' ;</p><p>foo( ) ;</p><p>bar( ) ;</p>",
494
+ "isRight": false
495
+ }
496
+ ],
497
+ "analysis": "<p>check named import:</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import</p><p>import {foo,bar} from 'path/universalContainersLib.js' ;</p><p>this one will only import foo and bar function, not all function, from the module</p>",
498
+ "hashCode": -1405888802
499
+ },
500
+ {
501
+ "describe": "<p>At Universal Containers, every team has its own way of copying JavaScript objects. The codesnippet shows an implementation from one team:</p><p>01 function Person( ) {</p><p>02 this.firstName = \"John\" ;</p><p>03 this.lastName = \"Doe\" ;</p><p>04 this.name = ( ) => {</p><p>05 console.log(`Hello ${this.firstName} ${this. lastName}`);</p><p>06 }</p><p>07 }</p><p>08</p><p>09 const john = new Person( ) ;</p><p>10 const dan = JSON.parse (JSON . stringify (john));</p><p>11 dan.firstName = 'Dan';</p><p>12 dan.name( ) ;</p><p>What is the output of the code execution?</p><p></p>",
502
+ "answerOptions": [
503
+ {
504
+ "describe": "<p>TypeError: Assignment to constant variable</p>",
505
+ "isRight": false
506
+ },
507
+ {
508
+ "describe": "<p>Hello Dan Doe</p>",
509
+ "isRight": false
510
+ },
511
+ {
512
+ "describe": "<p>TypeError: dan.name is not a function</p>",
513
+ "isRight": true
514
+ },
515
+ {
516
+ "describe": "<p>Hello John Doe</p>",
517
+ "isRight": false
518
+ }
519
+ ],
520
+ "analysis": "<p>line10 will convert john to a JSON Object and thus no such name function</p>",
521
+ "hashCode": -1654727508
522
+ },
523
+ {
524
+ "describe": "<p>Refer to the code below:</p><p>01 console. log(0) ;</p><p>02</p><p>03 setTimeout(( ) => {</p><p>04 console.log(1) ;</p><p>05 });</p><p>06</p><p>07 console.log(2) ;</p><p>08</p><p>09 setTimeout(( ) => {</p><p>10 console.log(3) ;</p><p>11 },0) ;</p><p>12</p><p>13 console.log(4) ;</p><p>In which sequence will the numbers be logged?</p><p></p>",
525
+ "answerOptions": [
526
+ {
527
+ "describe": "<p>0 1 2 3 4</p>",
528
+ "isRight": false
529
+ },
530
+ {
531
+ "describe": "<p>0 2 4 3 1</p>",
532
+ "isRight": false
533
+ },
534
+ {
535
+ "describe": "<p>0 2 4 1 3</p>",
536
+ "isRight": true
537
+ },
538
+ {
539
+ "describe": "<p>1 3 0 2 4</p>",
540
+ "isRight": false
541
+ }
542
+ ],
543
+ "analysis": "",
544
+ "hashCode": -87784688
545
+ },
546
+ {
547
+ "describe": "<p>A class was written to represent items purchase in an online store, and a second class representing items that are on sales at a discounted price. The constructor sets the name to the first value passed in. The pseudocode is below:</p><p>class Item {</p><p>constructor (name, price) {</p><p>... // Constructor Implementation</p><p>}</p><p>}</p><p>class SaleItem extends Item {</p><p>constructor (name, price, discount) {</p><p>... // Constructor Implementation</p><p>}</p><p>}</p><p>There is a new requirement for a developer to implement a description method that will return a brief description for Item and SaleItem.</p><p>01 let regItem = new Item('Scarf', 55) ;</p><p>02 let saleItem = new SaleItem('Shirt', 80, .1) ;</p><p>03 Item.prototype.description = function( ){ return 'This is a ' + this.name; }</p><p>04 console.log (regItem.description( ));</p><p>05 console.log(saleItem.description( )) ;</p><p>06</p><p>07 SaleItem. prototype. description = function( ) { return 'This is a discounted'+ this.name; }</p><p>08 console.log(regItem. description( ));</p><p>09 console.log (saleItem. description( )) ;</p><p>What is the output when executing the code above?</p><p></p>",
548
+ "answerOptions": [
549
+ {
550
+ "describe": "<p>This is a Scarf</p><p>Uncaught TypeError: saleItem.description is not a function</p><p>This is a Scarf</p><p>This is a discounted Shirt</p>",
551
+ "isRight": false
552
+ },
553
+ {
554
+ "describe": "<p>This is a Scarf</p><p>Uncaught TypeError: saleItem.description is not a function</p><p>This is a Shirt</p><p>This is a discounted Shirt</p>",
555
+ "isRight": false
556
+ },
557
+ {
558
+ "describe": "<p>This is a Scarf</p><p>This is a Shirt</p><p>This is a discounted Scarf</p><p>This is a discounted Shirt</p>",
559
+ "isRight": false
560
+ },
561
+ {
562
+ "describe": "<p>This is a Scarf</p><p>This is a Shirt</p><p>This is a Scarf</p><p>This is a discounted Shirt</p>",
563
+ "isRight": true
564
+ }
565
+ ],
566
+ "analysis": "",
567
+ "hashCode": 1276310888
568
+ },
569
+ {
570
+ "describe": "<p>A developer writes the code below to return a message to a user attempting to register a new username. If the username is available, a variable named msg is declared and assigned a value on line 03.</p><p>01 function getAvailabilityMessage (item) {</p><p>02 if (getAvailability (item)) {</p><p>03 var msg = \"Username available\" ;</p><p>04 }</p><p>05 return msg;</p><p>06 }</p><p>What is the value of msg when getAvailabilityMessage (\" newUserName\") is executed and getAvailability (\"newUserName\") returns true?</p><p></p>",
571
+ "answerOptions": [
572
+ {
573
+ "describe": "<p>undefined</p>",
574
+ "isRight": false
575
+ },
576
+ {
577
+ "describe": "<p>Username available</p>",
578
+ "isRight": true
579
+ },
580
+ {
581
+ "describe": "<p>msg is not defined</p>",
582
+ "isRight": false
583
+ },
584
+ {
585
+ "describe": "<p>NewUserName</p>",
586
+ "isRight": false
587
+ }
588
+ ],
589
+ "analysis": "",
590
+ "hashCode": -1439546997
591
+ },
592
+ {
593
+ "describe": "<p>Refer to the code below:</p><p>01 function changeValue (param) {</p><p>02 param = 5 ;</p><p>03 }</p><p>04 let a =10 ;</p><p>05 let b = a ;</p><p>06</p><p>07 changeValue (b) ;</p><p>08 const result =a+' - '+b ;</p><p>What is the value of result when the code executes?</p><p></p>",
594
+ "answerOptions": [
595
+ {
596
+ "describe": "<p>5-10</p>",
597
+ "isRight": false
598
+ },
599
+ {
600
+ "describe": "<p>10-5</p>",
601
+ "isRight": false
602
+ },
603
+ {
604
+ "describe": "<p>5-5</p>",
605
+ "isRight": false
606
+ },
607
+ {
608
+ "describe": "<p>10-10</p>",
609
+ "isRight": true
610
+ }
611
+ ],
612
+ "analysis": "",
613
+ "hashCode": 1902407972
614
+ },
615
+ {
616
+ "describe": "<p>Given the code block below:</p><p>01 function GameConsole (name) {</p><p>02 this.name = name ;</p><p>03 }</p><p>04</p><p>05 GameConsole.prototype.load = function (gamename) {</p><p>06 console.log(`${this.name} is loading a game: $ {gamename}...`) ;</p><p>07 }</p><p>08</p><p>09 function Console16bit (name) {</p><p>10 GameConsole.call (this, name) ;</p><p>11 }</p><p>12</p><p>13 Console16bit. prototype = Object. create (GameConsole. prototype) ;</p><p>14</p><p>15 // insert code here</p><p>16 console.log( ${this.name} is loading a cartridge game: ${gamename} ...`) ;</p><p>17 }</p><p>18</p><p>19 const console16bit = new Console16bit(' SNEGeneziz') ;</p><p>20 console16bit. load('Super Monic 3x Force') ;</p><p>What should a developer insert at line 15 to output the following message using the load method?</p><p>> SNEGeneziz is loading a cartridge game: Super Monic 3x Force. . .</p><p></p>",
617
+ "answerOptions": [
618
+ {
619
+ "describe": "<p>Console16bit.prototype.load = function (gamename) {</p>",
620
+ "isRight": true
621
+ },
622
+ {
623
+ "describe": "<p>Console16bit.prototype.load (gamename) = function( ) {</p>",
624
+ "isRight": false
625
+ },
626
+ {
627
+ "describe": "<p>Console16bit = Object.create (GameConsole .prototype).load =function (gamename) {</p>",
628
+ "isRight": false
629
+ },
630
+ {
631
+ "describe": "<p>Console16bit.prototype.load (gamename) {</p>",
632
+ "isRight": false
633
+ }
634
+ ],
635
+ "analysis": "",
636
+ "hashCode": -338334712
637
+ },
638
+ {
639
+ "describe": "<p>Refer to the following code that performs a basic mathematical operation on a provided input:</p><p>01 function calculate (num) {</p><p>02 return (num + 10) / 3;</p><p>03 }</p><p>How should line 02 be written to ensure that x evaluates to 6 in the line below?</p><p>let x = calculate(\"8\") ;</p><p></p>",
640
+ "answerOptions": [
641
+ {
642
+ "describe": "<p>return Number (num + 10) / 3;</p>",
643
+ "isRight": false
644
+ },
645
+ {
646
+ "describe": "<p>return Integer(num + 10) / 3;</p>",
647
+ "isRight": false
648
+ },
649
+ {
650
+ "describe": "<p>return (Number(num) + 10) / 3;</p>",
651
+ "isRight": true
652
+ },
653
+ {
654
+ "describe": "<p>return Number((num + 10) / 3);</p>",
655
+ "isRight": false
656
+ }
657
+ ],
658
+ "analysis": "",
659
+ "hashCode": -1251380895
660
+ },
661
+ {
662
+ "describe": "<p>A dveloper implements a fuction that adds a few values.</p><p>01 function sum (num) {</p><p>02 if (num === undefined) {</p><p>03 num = 0;</p><p>04 }</p><p>05 return function (num2, num3) {</p><p>06 if (num3 === undefined) {</p><p>07 num3=0</p><p>08 }</p><p>09 return num + num2 + num3 ;</p><p>10 }</p><p>11 }</p><p>Which three options can the developer invoke for this function to get a return value of 10?Choose 3 answers</p>",
663
+ "answerOptions": [
664
+ {
665
+ "describe": "<p>sum(10) ( )</p>",
666
+ "isRight": false
667
+ },
668
+ {
669
+ "describe": "<p>sum( ) (10)</p>",
670
+ "isRight": true
671
+ },
672
+ {
673
+ "describe": "<p>sum( )(5, 5)</p>",
674
+ "isRight": true
675
+ },
676
+ {
677
+ "describe": "<p>sum(5) (5)</p>",
678
+ "isRight": true
679
+ },
680
+ {
681
+ "describe": "<p>sum(5, 5) ( )</p>",
682
+ "isRight": false
683
+ }
684
+ ],
685
+ "analysis": "<p>sum(10) ( ) and sum(5, 5) ( ) return NaN</p>",
686
+ "hashCode": 1273586046
687
+ },
688
+ {
689
+ "describe": "<p>Given the code below:</p><p>01 setCurrentUrl( ) ;</p><p>02 console.log('The current URL is: ' + url);</p><p>03</p><p>04 function setCurrentUrl ( ) {</p><p>05 url = window. location.href ;</p><p>06 }</p><p>What happens when the code executes?</p><p></p>",
690
+ "answerOptions": [
691
+ {
692
+ "describe": "<p>The url variable has global scope and line 02 executes correctly.</p>",
693
+ "isRight": true
694
+ },
695
+ {
696
+ "describe": "<p>The url variable has local scope and line 02 throws an error.</p>",
697
+ "isRight": false
698
+ },
699
+ {
700
+ "describe": "<p>The url variale has local scope and line 02 executes correctly.</p>",
701
+ "isRight": false
702
+ },
703
+ {
704
+ "describe": "<p>The url variable has global scope and line 02 throws an error.</p>",
705
+ "isRight": false
706
+ }
707
+ ],
708
+ "analysis": "<p>Scope of the variables declared without var keyword become global irrespective of where it is declared. Global variables can be accessed from anywhere in the web page.</p>",
709
+ "hashCode": 1704091411
710
+ },
711
+ {
712
+ "describe": "<p>A developer wants to leverage a module to print a price in pretty format, and has imported a method as shown below:</p><p>import printPrice from ' /path PricePrettyPrint.js' ;</p><p>Based on the code, what must be true about the printPrice function of the PricePrettyPrint module for this import to work?</p><p></p>",
713
+ "answerOptions": [
714
+ {
715
+ "describe": "<p>printPrice must be a multi export</p>",
716
+ "isRight": false
717
+ },
718
+ {
719
+ "describe": "<p>printPrice must be an all export</p>",
720
+ "isRight": false
721
+ },
722
+ {
723
+ "describe": "<p>printPrice must be a named export</p>",
724
+ "isRight": false
725
+ },
726
+ {
727
+ "describe": "<p>printPrice must be the default export</p>",
728
+ "isRight": true
729
+ }
730
+ ],
731
+ "analysis": "<p>check default export:</p><p>https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export</p><p>if the printPrice is a named export, it would be: import { printPrice } from xxx;</p>",
732
+ "hashCode": -682085488
733
+ },
734
+ {
735
+ "describe": "<p>Given the JavaScript below:</p><p>01 function filterDOM (searchString) {</p><p>02 const parsedSearchstring = searchString && searchString. toLowerCase( ) ;</p><p>03 document . querySelectorAll (' .account') . forEach (account => {</p><p>04 const accountName = account . innerHTML. toLowerCase( ) ;</p><p>05 account.style.display = accountName . includes(parsedSearchString)? / * Insert code here */ ;</p><p>06 });</p><p>07 }</p><p>Which code should replace the placeholder comment on line 05 to hide accounts that do not match the search string?</p><p></p>",
736
+ "answerOptions": [
737
+ {
738
+ "describe": "<p>'block' : 'none'</p>",
739
+ "isRight": true
740
+ },
741
+ {
742
+ "describe": "<p>'none' : 'block'</p>",
743
+ "isRight": false
744
+ },
745
+ {
746
+ "describe": "<p>'visible' : 'hidden'</p>",
747
+ "isRight": false
748
+ },
749
+ {
750
+ "describe": "<p>'hidden' : 'visible'</p>",
751
+ "isRight": false
752
+ }
753
+ ],
754
+ "analysis": "<p>check HTML style dispay property:</p><p>https://www.w3schools.com/JSREF/prop_style_display.asp</p><p>no 'hidden' or 'visible' property</p>",
755
+ "hashCode": 977031262
756
+ },
757
+ {
758
+ "describe": "<p>Which of the following can best describe a callback function?</p><p>A</p>",
759
+ "answerOptions": [
760
+ {
761
+ "describe": "<p>function passed into a function to be called later.</p>",
762
+ "isRight": true
763
+ },
764
+ {
765
+ "describe": "<p>A synchronous function that can be executed along with the main thread.</p>",
766
+ "isRight": false
767
+ },
768
+ {
769
+ "describe": "<p>A function that can be easily chained to another function.</p>",
770
+ "isRight": true
771
+ },
772
+ {
773
+ "describe": "<p>A function to be executed when there is an error.</p>",
774
+ "isRight": false
775
+ }
776
+ ],
777
+ "analysis": "<p>A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.</p><p>Here is a quick example:</p><p>function greeting(name) {</p><p>alert('Hello ' + name);</p><p>}</p><p>function processUserInput(callback) {</p><p>var name = prompt('Please enter your name.');</p><p>callback(name);</p><p>}</p><p>processUserInput(greeting);</p><p>The above example is a synchronous callback, as it is executed immediately. However, that callbacks are often used to continue code execution after an asynchronous operation has completed — these are called asynchronous callbacks. A good example is the callback functions executed inside a .then() block chained onto the end of a promise after that promise fulfills or rejects. Another example would be the setTimeout function.</p>",
778
+ "hashCode": 121790993
779
+ },
780
+ {
781
+ "describe": "<p>A developer creates a class that represents a blog post based on the requirements that a Post should have a body, author, and view count. The code is shown below:</p><p>01 class Post {</p><p>02 // Insert code here</p><p>03 this.body = body;</p><p>04 this.author = author;</p><p>05 this. viewCount = viewCount;</p><p>06 }</p><p>07 }</p><p>Which statement should be inserted in the placeholder on line 02 to allow for a variable to be set to a new instance of a Post with the three attributes correctly populated?</p><p></p>",
782
+ "answerOptions": [
783
+ {
784
+ "describe": "<p>function Post (body, author, viewCount) {</p>",
785
+ "isRight": false
786
+ },
787
+ {
788
+ "describe": "<p>super (body, author, viewCount) {</p>",
789
+ "isRight": false
790
+ },
791
+ {
792
+ "describe": "<p>constructor() {</p>",
793
+ "isRight": false
794
+ },
795
+ {
796
+ "describe": "<p>constructor (body, author, viewCount) {</p>",
797
+ "isRight": true
798
+ }
799
+ ],
800
+ "analysis": "",
801
+ "hashCode": 201627949
802
+ },
803
+ {
804
+ "describe": "<p>Which of the following is the correct use of template literals?</p><p></p>",
805
+ "answerOptions": [
806
+ {
807
+ "describe": "<p>let str = \"Fifteen is ${a + b} and not ${2 * a + b}.\";</p>",
808
+ "isRight": false
809
+ },
810
+ {
811
+ "describe": "<p>let str = `Fifteen is ${a + b} and not ${2 * a + b}.`;</p>",
812
+ "isRight": true
813
+ },
814
+ {
815
+ "describe": "<p>let str = `Fifteen is $(a + b) and not $(2 * a + b).`</p>",
816
+ "isRight": false
817
+ },
818
+ {
819
+ "describe": "<p>let str = ${`Fifteen is ` + ( a + b ) + ` and not ` + (2 * a + b) + `.`};</p>",
820
+ "isRight": false
821
+ }
822
+ ],
823
+ "analysis": "<p>Template literals are enclosed by the backtick (` `) and contain placeholders indicated by dollar sign and curly braces like ${expression}.</p><p>let str = `Fifteen is ${a + b} and not ${2 * a + b}.` is the right way of using template literals with placeholders.</p><p>let str = \"Fifteen is ${a + b} and not ${2 * a + b}.\" is incorrect because it is not enclosed by backticks but rather regular double quotes.</p><p>let str = ${`Fifteen is ` + ( a + b ) + ` and not ` + (2 * a + b) + `.`}; is incorrect as the dollar sign and curly braces are not inside the backticks.</p><p>let str = `Fifteen is $(a + b) and not $(2 * a + b).` is incorrect because the placeholder is enclosed by round brackets, not curly braces.</p>",
824
+ "hashCode": -156482148
825
+ },
826
+ {
827
+ "describe": "<p>A developer would like to understand the scope of functions, hence he wrote a simple script:</p><p>var p = 5;</p><p>function func() {</p><p>var p = 9;</p><p>function decl() {</p><p>console.log(p);</p><p>}</p><p>var expr = function() {</p><p>console.log(p);</p><p>};</p><p>var cons = new Function('\\tconsole.log(p);');</p><p>decl();</p><p>expr();</p><p>cons();</p><p>}</p><p>func();</p><p>What is the correct output that will be displayed on the console when the code is executed?</p><p></p>",
828
+ "answerOptions": [
829
+ {
830
+ "describe": "<p>9 9 5</p>",
831
+ "isRight": true
832
+ },
833
+ {
834
+ "describe": "<p>9 9 9</p>",
835
+ "isRight": false
836
+ },
837
+ {
838
+ "describe": "<p>9 5 9</p>",
839
+ "isRight": false
840
+ },
841
+ {
842
+ "describe": "<p>5 5 9</p>",
843
+ "isRight": false
844
+ }
845
+ ],
846
+ "analysis": "<p>The correct output of the script is 9 9 5.</p><p>A function defined by a function expression (indicated by expr()) or by a function declaration (indicated by decl()) inherits the current scope. That is, the function forms a closure. On the other hand, a function defined by a Function constructor (indicated by cons()) does not inherit any scope other than the global scope (which all functions inherit).</p>",
847
+ "hashCode": -1353616245
848
+ },
849
+ {
850
+ "describe": "<p>const target = { a: 1, b: 2 };</p><p>const source = { b: 4, c: 5 };</p><p>const returnedTarget = Object.assign(target, source);</p><p>target.a = 6;</p><p>source.c = 12;</p><p>console.log(returnedTarget.a);</p><p>console.log(returnedTarget.b);</p><p>console.log(returnedTarget.c);</p><p>Given the code above, what would be printed out in the console?</p><p></p>",
851
+ "answerOptions": [
852
+ {
853
+ "describe": "<p>6 4 12</p>",
854
+ "isRight": false
855
+ },
856
+ {
857
+ "describe": "<p>1 4 5</p>",
858
+ "isRight": false
859
+ },
860
+ {
861
+ "describe": "<p>1 2 5</p>",
862
+ "isRight": false
863
+ },
864
+ {
865
+ "describe": "<p>6 4 5</p>",
866
+ "isRight": true
867
+ }
868
+ ],
869
+ "analysis": "<p>The correct output sequence will be 6, 4 and 5.</p><p>Object.assign(dest, [src1, src2, src3…]) copies the properties of all source objects into the target destination (first parameter) which is also the target object in this scenario. Since the target object is assigned to returnedTarget, the change of properties in target object will also reflect on returnedTarget object, hence we get 6, 4, 5. The change of properties in source object does not reflect on returnedTarget because the source properties are copied by value into target object which then assigned to returnedTarget object.</p>",
870
+ "hashCode": 694078930
871
+ },
872
+ {
873
+ "describe": "<p>Which of the following statements regarding an object property is correct? Choose 2 answers.</p><p></p>",
874
+ "answerOptions": [
875
+ {
876
+ "describe": "<p>In order to remove an object property, we could use delete operator to remove the property.</p>",
877
+ "isRight": true
878
+ },
879
+ {
880
+ "describe": "<p>An object declared as const cannot be modified.</p>",
881
+ "isRight": false
882
+ },
883
+ {
884
+ "describe": "<p>You cannot use specific language-reserved words such as \"for\", \"let\", \"return\" and etc. for an object property.</p>",
885
+ "isRight": false
886
+ },
887
+ {
888
+ "describe": "<p>It is possible to use square brackets in an object literal when creating an object.</p>",
889
+ "isRight": true
890
+ }
891
+ ],
892
+ "analysis": "<p>An object property can be removed by using delete operator. Here’s an example:</p><p>let user = { // an object</p><p>name: \"John\", // by key \"name\" store value \"John\"</p><p>age: 30 // by key \"age\" store value 30</p><p>};</p><p>delete user.age;</p><p>When an object is declared as const, it can be modified actually. The const fixes the value of the object, not its contents. For example:</p><p>const user = {</p><p>name: \"John\"</p><p>};</p><p>user.name = \"Pete\"; // no error is thrown</p><p>user = {}; // uncaught TypeError: Assignment to constant variable</p><p>It is possible to use square brackets in an object literal when creating an object. For example:</p><p>let fruit = prompt(\"Which fruit to buy?\", \"apple\");</p><p>let bag = {</p><p>[fruit]: 5, // the name of the property is taken from the variable fruit</p><p>};</p><p>console.log( bag.apple ); // 5 if fruit=\"apple\"</p><p>a variable cannot have a name equal to one of language-reserved words like “for”, “let”, “return” etc. But for an object property, there’s no such restriction:</p><p>// these properties are all right</p><p>let obj = {</p><p>for: 1,</p><p>let: 2,</p><p>return: 3</p><p>};</p><p>console.log( obj.for + obj.let + obj.return ); // 6</p>",
893
+ "hashCode": 542607607
894
+ },
895
+ {
896
+ "describe": "<p>Which of the following regarding function is correct? Choose 3 answers.</p>",
897
+ "answerOptions": [
898
+ {
899
+ "describe": "<p>The default parameter in the function will always be evaluated.</p>",
900
+ "isRight": false
901
+ },
902
+ {
903
+ "describe": "<p>One function may not be accessed outer variables if the variable is declared with \"let\" keyword.</p>",
904
+ "isRight": false
905
+ },
906
+ {
907
+ "describe": "<p>jQuery library defines a function with \"$\" while the Lodash library defines its main core function with \"_\".</p>",
908
+ "isRight": true
909
+ },
910
+ {
911
+ "describe": "<p>Never add a newline between return and the value.</p>",
912
+ "isRight": true
913
+ },
914
+ {
915
+ "describe": "<p>If a function does not return a value, it is the same as if it returns undefined.</p>",
916
+ "isRight": true
917
+ }
918
+ ],
919
+ "analysis": "<p>A default parameter will be evaluated if the function is called without the respective parameter</p><p>If a function does not return a value, it is the same as if it returns undefined</p><p>An empty return is also the same as return undefined</p><p>jQuery library defines a function with “$” while the Lodash library defines its main core function with “_”.</p><p>You should not add a newline between return and the value you want to return. Reason being, JavaScript might interpret your code differently. For example, you want to return a long expression like this:</p><p>return</p><p>(some + long + expression + or + whatever * f(a) + f(b))</p><p>The code will not work as expected. JavaScript assumes there is a semicolon after return keyword, which effectively becomes an empty return. However, if you really want to do so, make sure you wrap your expression at the same line as return keyword like this:</p><p>return (</p><p>some + long + expression</p><p>+ or +</p><p>whatever * f(a) + f(b)</p><p>)</p><p>That way, JavaScript will not misinterpret your code.</p>",
920
+ "hashCode": 1548391267
921
+ },
922
+ {
923
+ "describe": "<p>A developer wants to use a module called DatePrettyPrint. This module exports one default function called printDate(). How can a developer import and use the printDate() function?</p><p></p>",
924
+ "answerOptions": [
925
+ {
926
+ "describe": "<p>import printDate from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate();</p>",
927
+ "isRight": false
928
+ },
929
+ {
930
+ "describe": "<p>import printDate from '/path/DatePrettyPrint.js'; printDate();</p>",
931
+ "isRight": true
932
+ },
933
+ {
934
+ "describe": "<p>import DatePrettyPrint from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate();</p>",
935
+ "isRight": false
936
+ },
937
+ {
938
+ "describe": "<p>import printDate() from '/path/DatePrettyPrint.js'; printDate();</p>",
939
+ "isRight": false
940
+ }
941
+ ],
942
+ "analysis": "<p>import printDate from '/path/DatePrettyPrint.js'; printDate(); is the simplest version of code for importing the default.</p><p>import printDate() from '/path/DatePrettyPrint.js'; printDate(); is incorrect. When naming the export function the parentheses are not needed.</p><p>import DatePrettyPrint from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate(); is incorrect. You must call the methods directly or use the * to import all methods.</p><p>import printDate from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate(); is incorrect. Once imported by name, you must call the imported method directly by name.</p>",
943
+ "hashCode": -388162408
944
+ },
945
+ {
946
+ "describe": "<p>Given the code below:</p><p>let x = 2;</p><p>let y = 3;</p><p>let add = x => y => x + y;</p><p>The “add” variable is an arrow function which is used to sum two numbers. What is the correct way of calling this function? Choose 1 answer.</p><p></p>",
947
+ "answerOptions": [
948
+ {
949
+ "describe": "<p>add(x)(y)</p>",
950
+ "isRight": true
951
+ },
952
+ {
953
+ "describe": "<p>add()</p>",
954
+ "isRight": false
955
+ },
956
+ {
957
+ "describe": "<p>add.x.y</p>",
958
+ "isRight": false
959
+ },
960
+ {
961
+ "describe": "<p>add(x, y)</p>",
962
+ "isRight": false
963
+ }
964
+ ],
965
+ "analysis": "<p>The correct way of calling this add function is add(x)(y). The arrow function is equivalent to the following code:</p><p>const add = function (x) {</p><p>return function (y) {</p><p>return x + y;</p><p>}</p><p>}</p><p>This is also called “Curried Function“. Currying is a transform that makes f(a, b, c) callable as f(a)(b)(c). The advantage of currying is that it allows us to easily get the partials. For example, we might just want to call f(a) or f(a)(b), depending on our own needs.</p>",
966
+ "hashCode": 972403238
967
+ },
968
+ {
969
+ "describe": "<p>Which syntax for accessing the property of an object in JavaScript is correct? Choose 3 answers.</p>",
970
+ "answerOptions": [
971
+ {
972
+ "describe": "<p>objectName[\"property\"] // person[\"age\"]</p>",
973
+ "isRight": true
974
+ },
975
+ {
976
+ "describe": "<p>objectName.property // person.age</p>",
977
+ "isRight": true
978
+ },
979
+ {
980
+ "describe": "<p>${objectName(property)} // ${person(property)}</p>",
981
+ "isRight": false
982
+ },
983
+ {
984
+ "describe": "<p>objectName[expression] // x = \"age\"; person[x]</p>",
985
+ "isRight": true
986
+ },
987
+ {
988
+ "describe": "<p>objectName->property // person->age</p>",
989
+ "isRight": false
990
+ }
991
+ ],
992
+ "analysis": "<p>The correct syntax for accessing the property of an object is:</p><p>objectName.property</p><p>objectName[\"property\"]</p><p>objectName[expression]</p><p>objectName->property is invalid in JavaScript, though it might be valid for some other programming languages such as PHP.</p><p>There is nothing like ${person(property)} in JavaScript or any known programming languages.</p>",
993
+ "hashCode": -990895308
994
+ },
995
+ {
996
+ "describe": "<p>Which statement sorts the following number array so it is in ascending order?</p><p>const arr = [7, 3, 400, 10];</p><p>Choose 1 answer.</p><p></p>",
997
+ "answerOptions": [
998
+ {
999
+ "describe": "<p>arr.sort((a, b) => a < b);[/su_highlight]</p>",
1000
+ "isRight": false
1001
+ },
1002
+ {
1003
+ "describe": "<p>arr.sort();</p>",
1004
+ "isRight": false
1005
+ },
1006
+ {
1007
+ "describe": "<p>arr.sort((a, b) => a – b);</p>",
1008
+ "isRight": true
1009
+ },
1010
+ {
1011
+ "describe": "<p>arr.sort((a, b) => b – a);</p>",
1012
+ "isRight": false
1013
+ }
1014
+ ],
1015
+ "analysis": "<p>By default, the sort() function sorts values as strings.</p><p>arr.sort( (a, b) => a – b); is the correct answer. The compare function passed in sort() defines an alternative sort order.</p><p>arr.sort(); is incorrect because the sort() function sorts values as strings, which will sort this as [10, 3, 400, 7].</p><p>arr.sort((a, b) => a < b); is incorrect. The compare function expects a positive, negative, or 0 to be returned, not the Boolean expression.</p><p>arr.sort((a, b) => b – a); is incorrect. The compare function will actually reverse the order of the numbers.</p>",
1016
+ "hashCode": 577492143
1017
+ },
1018
+ {
1019
+ "describe": "<p>You are given the following code:</p><p>let user = { name: \"John\"};</p><p>user.canView = false;</p><p>user.canEdit = false;</p><p>let permissions1 = { canView: true, canEdit: false };</p><p>let permissions2 = { canView: false, canEdit: true };</p><p>Object.assign(user, permissions1, permissions2);</p><p>console.log(user);</p><p>What will the output be when the code is executed? Choose 1 answer.</p><p></p>",
1020
+ "answerOptions": [
1021
+ {
1022
+ "describe": "<p>{</p><p>name:\"John\",</p><p>canView:false,</p><p>canEdit:false</p><p>}</p>",
1023
+ "isRight": false
1024
+ },
1025
+ {
1026
+ "describe": "<p>{</p><p>name:\"John\",</p><p>canView:true,</p><p>canEdit:false</p><p>}</p>",
1027
+ "isRight": false
1028
+ },
1029
+ {
1030
+ "describe": "<p>{</p><p>name:\"John\",</p><p>canView:false,</p><p>canEdit:true</p><p>}</p>",
1031
+ "isRight": true
1032
+ },
1033
+ {
1034
+ "describe": "<p>{</p><p>name:\"John\",</p><p>canView:true,</p><p>canEdit:true</p><p>}</p>",
1035
+ "isRight": false
1036
+ }
1037
+ ],
1038
+ "analysis": "<p>The correct answer is:</p><p>{</p><p>name:\"John\",</p><p>canView:false,</p><p>canEdit:true</p><p>}</p><p>Object.assign() method copies all enumerable own properties from one or more source objects to a target object. The properties are overwritten by other objects that have the same properties later in the order of the parameters.</p>",
1039
+ "hashCode": -1848566150
1040
+ },
1041
+ {
1042
+ "describe": "<p>Given the following Car constructor:</p><p>function Car(size, model) {</p><p>this.size= size;</p><p>this.model = model;</p><p>}</p><p>Which method creates a new instance of the object? Choose 1 answer.</p><p></p>",
1043
+ "answerOptions": [
1044
+ {
1045
+ "describe": "<p>new Car('large', 'Audi');</p>",
1046
+ "isRight": true
1047
+ },
1048
+ {
1049
+ "describe": "<p>Object.prototype(Car);</p>",
1050
+ "isRight": false
1051
+ },
1052
+ {
1053
+ "describe": "<p>Object.new(Car);</p>",
1054
+ "isRight": false
1055
+ },
1056
+ {
1057
+ "describe": "<p>Object.create('Car');</p>",
1058
+ "isRight": false
1059
+ }
1060
+ ],
1061
+ "analysis": "<p>new Car('large', 'Audi'); is the correct way of creating a new instance of object.</p><p>Object.create('Car'); is incorrect. The argument for Object.create() method should be a new object with the specified prototype object and properties.</p><p>Object.prototype(Animal); is incorrect. Prototypes are usually used to add methods to existing constructors.</p><p>Object.new(Animal); is incorrect as well. There is no Object.new() in JavaScript.</p>",
1062
+ "hashCode": -1880423419
1063
+ },
1064
+ {
1065
+ "describe": "<p>function func() {</p><p>try {</p><p>return 1;</p><p>} finally {</p><p>console.log( 'finally' );</p><p>}</p><p>}</p><p>console.log( func() );</p><p>Which of the following statement is correct when the code above is executed? Choose 1 answer.</p><p></p>",
1066
+ "answerOptions": [
1067
+ {
1068
+ "describe": "<p>The console output will display \"1\" first, then \"finally\".</p>",
1069
+ "isRight": false
1070
+ },
1071
+ {
1072
+ "describe": "<p>The console output will display \"finally\" first, then \"1\".</p>",
1073
+ "isRight": true
1074
+ },
1075
+ {
1076
+ "describe": "<p>The finally block will not be executed because the function is returned before the finally code block.</p>",
1077
+ "isRight": false
1078
+ },
1079
+ {
1080
+ "describe": "<p>The code will not work because it is missing the catch block.</p>",
1081
+ "isRight": false
1082
+ }
1083
+ ],
1084
+ "analysis": "<p>Finally block will be executed before the code returns to the outer code, hence the output will display “finally” first, then “1”.</p><p>Catch block is not mandatory if we are not to catch the error when executing the code.</p>",
1085
+ "hashCode": -1140449447
1086
+ },
1087
+ {
1088
+ "describe": "<p>Which of the following regarding Classes in JavaScript is correct? Choose 3 answers.</p>",
1089
+ "answerOptions": [
1090
+ {
1091
+ "describe": "<p>Class expressions can be named or unnamed and the name given to a named class expression is local to the class's body.</p>",
1092
+ "isRight": true
1093
+ },
1094
+ {
1095
+ "describe": "<p>JavaScript classes are introduced in ECMAScript 2016 Edition.</p>",
1096
+ "isRight": false
1097
+ },
1098
+ {
1099
+ "describe": "<p>Classes are the \"special functions\" which are primarily syntactical sugar over JavaScript's existing prototype-based inheritance.</p>",
1100
+ "isRight": true
1101
+ },
1102
+ {
1103
+ "describe": "<p>There are two ways to define a class: class declaration and class expression.</p>",
1104
+ "isRight": true
1105
+ },
1106
+ {
1107
+ "describe": "<p>The difference between function declarations and class declarations is that class declarations are hoisted and function declarations are not.</p>",
1108
+ "isRight": false
1109
+ }
1110
+ ],
1111
+ "analysis": "<p>Classes are the “special functions” which are primarily syntactical sugar over JavaScript’s existing prototype-based inheritance. The class syntax does not introduce a new object-oriented inheritance model to JavaScript.</p><p>The class syntax has two components: class expressions and class declarations.</p><p>Class declaration example:</p><p>// class declaration</p><p>class Rectangle {</p><p>constructor(height, width) {</p><p>this.height = height;</p><p>this.width = width;</p><p>}</p><p>}</p><p>Class expression examples:</p><p>// unnamed class expression</p><p>let Rectangle = class {</p><p>constructor(height, width) {</p><p>this.height = height;</p><p>this.width = width;</p><p>}</p><p>};</p><p>// named class expression</p><p>let Rectangle = class Rectangle2 {</p><p>constructor(height, width) {</p><p>this.height = height;</p><p>this.width = width;</p><p>}</p><p>};</p><p>Function declarations are hoisted but class declarations are not. The following example with throw an error:</p><p>const p = new Rectangle(); // ReferenceError</p><p>class Rectangle { }</p><p>JavaScript classes are introduced in ECMAScript 2015, also known as JavaScript ES6.</p>",
1112
+ "hashCode": -104347577
1113
+ },
1114
+ {
1115
+ "describe": "<p>Which of the following statements is correct regarding the JSON and object literal notation? Choose 2 answers.</p><p></p>",
1116
+ "answerOptions": [
1117
+ {
1118
+ "describe": "<p>JSON and object literal notation are the same.</p>",
1119
+ "isRight": false
1120
+ },
1121
+ {
1122
+ "describe": "<p>Object literal notation spec is based on JSON.</p>",
1123
+ "isRight": false
1124
+ },
1125
+ {
1126
+ "describe": "<p>Object literal notation is a programming syntax.</p>",
1127
+ "isRight": true
1128
+ },
1129
+ {
1130
+ "describe": "<p>JSON is a data-interchange format.</p>",
1131
+ "isRight": true
1132
+ }
1133
+ ],
1134
+ "analysis": "<p>JSON (JavaScript Object Notation) is a data-interchange format.</p><p>Object literal notation is a programming syntax.</p><p>JSON and object literal notation resemble each other, but they’re not the same.</p><p>JSON spec is based on object-literal notation, not the other way round.</p>",
1135
+ "hashCode": 1491692238
1136
+ },
1137
+ {
1138
+ "describe": "<p>Which of the following is a feature of prototypical inheritance?</p><p>A</p>",
1139
+ "answerOptions": [
1140
+ {
1141
+ "describe": "<p>class that defines all objects of a common type.</p>",
1142
+ "isRight": false
1143
+ },
1144
+ {
1145
+ "describe": "<p>Module code artifacts that define a single reusable feature.</p>",
1146
+ "isRight": false
1147
+ },
1148
+ {
1149
+ "describe": "<p>Architecture that ensures data from some objects can be passed to other objects.</p>",
1150
+ "isRight": false
1151
+ },
1152
+ {
1153
+ "describe": "<p>An in-memory object that defines properties and functions of other objects.</p>",
1154
+ "isRight": true
1155
+ }
1156
+ ],
1157
+ "analysis": "<p>Despite not having classes as defined by classical languages, JavaScript still has an inheritance model which is called prototype inheritance. A prototype is another object that sits in memory and defines properties or functions that other objects inherit if they share the same prototype.</p>",
1158
+ "hashCode": 2035832970
1159
+ },
1160
+ {
1161
+ "describe": "<p>Which of the following can be best described modules? Choose 2 answers.</p><p></p>",
1162
+ "answerOptions": [
1163
+ {
1164
+ "describe": "<p>Modules work on HTTP, HTTPS, and website document that stores locally on your computer.</p>",
1165
+ "isRight": false
1166
+ },
1167
+ {
1168
+ "describe": "<p>Modules can be set \"use strict\" optionally.</p>",
1169
+ "isRight": false
1170
+ },
1171
+ {
1172
+ "describe": "<p>One module is just a file that may contain a class or a library of functions for a specific purpose.</p>",
1173
+ "isRight": true
1174
+ },
1175
+ {
1176
+ "describe": "<p>Modules can load each other and special directives such as export and import can be used interchangeably.</p>",
1177
+ "isRight": true
1178
+ }
1179
+ ],
1180
+ "analysis": "<p>A module is just a file. One script is one module. As simple as that. A module may contain a class or a library of functions for a specific purpose.</p><p>We must tell the browser that a script should be treated as a module by using the attribute</p>",
1181
+ "hashCode": -514234380
1182
+ },
1183
+ {
1184
+ "describe": "<p>The developer has a function that prints \"Hello\" to an input name. To test this, the developer</p><p>created a function that returns \"World\". However, the following snippet does not print \"Hello World\".</p><p>01 const sayHello = (name) => {</p><p>02 console.log('Hello ', name) ;</p><p>03 };</p><p>04</p><p>05 const world= ( ) => {</p><p>06 return 'World' ;</p><p>07 } ;</p><p>08</p><p>09 sayHello (world) ;</p><p>What can the developer do to change the code to print \"Hello World\"?</p><p></p>",
1185
+ "answerOptions": [
1186
+ {
1187
+ "describe": "<p>Change line 7 to } ( ) ;</p>",
1188
+ "isRight": false
1189
+ },
1190
+ {
1191
+ "describe": "<p>Change line 5 to function world( ) {</p>",
1192
+ "isRight": false
1193
+ },
1194
+ {
1195
+ "describe": "<p>Change line 2 to consololoe. log('Hello', name( ));</p>",
1196
+ "isRight": true
1197
+ },
1198
+ {
1199
+ "describe": "<p>Change line 9 to sayHello(world)( ) ;</p>",
1200
+ "isRight": false
1201
+ }
1202
+ ],
1203
+ "analysis": "<p>world is a function, call sayHello and pass in the world function will print out the function body itself</p>",
1204
+ "hashCode": -320362966
1205
+ },
1206
+ {
1207
+ "describe": "<p>Refer to the code below:</p><p>01 function foo( ) {</p><p>02 const a = 2;</p><p>03 function bar( ) {</p><p>04 console.log(a) ;</p><p>05 }</p><p>06 return bar;</p><p>07 }</p><p>Why does the function bar have access to variable a?</p><p></p>",
1208
+ "answerOptions": [
1209
+ {
1210
+ "describe": "<p>Inner function's scope</p>",
1211
+ "isRight": false
1212
+ },
1213
+ {
1214
+ "describe": "<p>Hoisting</p>",
1215
+ "isRight": false
1216
+ },
1217
+ {
1218
+ "describe": "<p>Outer function's scope</p>",
1219
+ "isRight": true
1220
+ },
1221
+ {
1222
+ "describe": "<p>Prototype chain</p>",
1223
+ "isRight": false
1224
+ }
1225
+ ],
1226
+ "analysis": "<p>check JavaScript Closure</p><p>a closure gives you access to an outer function's scope from an inner function.</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures</p>",
1227
+ "hashCode": 2049249383
1228
+ },
1229
+ {
1230
+ "describe": "<p>A developer uses a parsed JSON string to work with user informationas in the block below:</p><p>01 const userInformation = {</p><p>02 \"id\" : \"user-01\",</p><p>03 \"email\" : \"user01@universalcontainers . demo\" ,</p><p>04 \"age\" : 25</p><p>05 };</p><p>Which two options access the email attriuite in the object? Choose 2 answers</p><p></p>",
1231
+ "answerOptions": [
1232
+ {
1233
+ "describe": "<p>userInformation[\"email\"]</p>",
1234
+ "isRight": true
1235
+ },
1236
+ {
1237
+ "describe": "<p>userInformation. email</p>",
1238
+ "isRight": true
1239
+ },
1240
+ {
1241
+ "describe": "<p>userInformation. get (\"email\")</p>",
1242
+ "isRight": false
1243
+ },
1244
+ {
1245
+ "describe": "<p>userInformation[email]</p>",
1246
+ "isRight": false
1247
+ }
1248
+ ],
1249
+ "analysis": "",
1250
+ "hashCode": 415077733
1251
+ },
1252
+ {
1253
+ "describe": "<p>Refer to the code below:</p><p>flag( ) ;</p><p>anotherFlag( ) ;</p><p>function flag( ) {</p><p>console.log('flag') ;</p><p>}</p><p>const anotherFlag = ( ) => {</p><p>console.log( 'another flag') ;</p><p>}</p><p>What is result of the code block?</p><p></p>",
1254
+ "answerOptions": [
1255
+ {
1256
+ "describe": "<p>An error is thrown.</p>",
1257
+ "isRight": false
1258
+ },
1259
+ {
1260
+ "describe": "<p>The console logs only 'flag'.</p>",
1261
+ "isRight": false
1262
+ },
1263
+ {
1264
+ "describe": "<p>The console logs 'flag' and then an error is thrown.</p>",
1265
+ "isRight": true
1266
+ },
1267
+ {
1268
+ "describe": "<p>The console logs 'flag' and 'another flag'.</p>",
1269
+ "isRight": false
1270
+ }
1271
+ ],
1272
+ "analysis": "<p>const declarations must be initialized</p><p>const initialization must be happening before calling</p><p>flag() is called first and output 'flag', then call anotherFlag(), get error: Cannot access 'anotherFlag' before initialization</p>",
1273
+ "hashCode": -926091128
1274
+ },
1275
+ {
1276
+ "describe": "<p>Refer to the following code:</p><p>01 function test(val) {</p><p>02 if (val === undefined) {</p><p>03 return 'Undefined value!' ;</p><p>04 }</p><p>05 if (val === null) {</p><p>06 return 'Null value!' ;</p><p>07 }</p><p>08 return val;</p><p>09 }</p><p>10</p><p>11 let x ;</p><p>12</p><p>13 test(x) ;</p><p>What is returned by the function call on line 13?</p><p></p>",
1277
+ "answerOptions": [
1278
+ {
1279
+ "describe": "<p>undefined</p>",
1280
+ "isRight": false
1281
+ },
1282
+ {
1283
+ "describe": "<p>Line 13 throws an error.</p>",
1284
+ "isRight": false
1285
+ },
1286
+ {
1287
+ "describe": "<p>'Null value!'</p>",
1288
+ "isRight": false
1289
+ },
1290
+ {
1291
+ "describe": "<p>'Undefined value!'</p>",
1292
+ "isRight": true
1293
+ }
1294
+ ],
1295
+ "analysis": "<p>line 11, x is undefined</p>",
1296
+ "hashCode": -173811572
1297
+ },
1298
+ {
1299
+ "describe": "<p>Refer to the code below:</p><p>01 let first = 'Who';</p><p>02 let second = 'What';</p><p>03 try {</p><p>04 try {</p><p>05 throw new Error('Sad trombone');</p><p>06 } catch (err) {</p><p>07 first = 'Why' ;</p><p>08 } finally {</p><p>09 second = 'When';</p><p>10 }</p><p>11 } catch (err) {</p><p>12 second = 'Where' ;</p><p>13 }</p><p>What are the values for first and second once the code executes?</p><p></p>",
1300
+ "answerOptions": [
1301
+ {
1302
+ "describe": "<p>first is Why and second is Where.</p>",
1303
+ "isRight": false
1304
+ },
1305
+ {
1306
+ "describe": "<p>first is Who and second is When.</p>",
1307
+ "isRight": false
1308
+ },
1309
+ {
1310
+ "describe": "<p>first is Why and second is When.</p>",
1311
+ "isRight": true
1312
+ },
1313
+ {
1314
+ "describe": "<p>first is Who and second is Where.</p>",
1315
+ "isRight": false
1316
+ }
1317
+ ],
1318
+ "analysis": "<p>inner try block throws an error, so first was changed to Why</p><p>finally block will be executed next, so second will be changed to When</p><p>outter catch block is skipped</p>",
1319
+ "hashCode": 255077162
1320
+ },
1321
+ {
1322
+ "describe": "<p>Refer to the following object:</p><p>01 const cat = {</p><p>02 firstName: ' Fancy' ,</p><p>03 lastName: ' Whiskers' ,</p><p>04 get fullName( ) {</p><p>05 return this. firstName + ' ' + this.lastName ;</p><p>06 }</p><p>07 };</p><p>How can a developer access the fullName property for cat?</p><p></p>",
1323
+ "answerOptions": [
1324
+ {
1325
+ "describe": "<p>cat.fullName</p>",
1326
+ "isRight": true
1327
+ },
1328
+ {
1329
+ "describe": "<p>cat.get.fullName</p>",
1330
+ "isRight": false
1331
+ },
1332
+ {
1333
+ "describe": "<p>cat.fullName( )</p>",
1334
+ "isRight": false
1335
+ },
1336
+ {
1337
+ "describe": "<p>cat.function.fullName( )</p>",
1338
+ "isRight": false
1339
+ }
1340
+ ],
1341
+ "analysis": "<p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get</p>",
1342
+ "hashCode": 206805179
1343
+ },
1344
+ {
1345
+ "describe": "<p>Cloud Kicks has a class to represent items for sale in an online store, as shown belows:</p><p>01 class Item {</p><p>02 constructor (name, price) {</p><p>03 this.name = name;</p><p>04 this.price = price;</p><p>05 }</p><p>06</p><p>07 formattedPrice( ) {</p><p>08 return '$' + string (this.price) ;</p><p>09 }</p><p>10 }</p><p>A new business requirement comes in that requests a ClothingItem class, that should have all of the properties and methods of the Item class, but will also have properties that are specific to clothes.Which line of code properly declares the ClothingItem class such that it inherits from Item?</p><p></p>",
1346
+ "answerOptions": [
1347
+ {
1348
+ "describe": "<p>class ClothingItem super Item {</p>",
1349
+ "isRight": false
1350
+ },
1351
+ {
1352
+ "describe": "<p>class ClothingItem implements Item {</p>",
1353
+ "isRight": false
1354
+ },
1355
+ {
1356
+ "describe": "<p>class ClothingItem extends Item {</p>",
1357
+ "isRight": true
1358
+ },
1359
+ {
1360
+ "describe": "<p>class ClothingItem {</p>",
1361
+ "isRight": false
1362
+ }
1363
+ ],
1364
+ "analysis": "",
1365
+ "hashCode": 1529418526
1366
+ },
1367
+ {
1368
+ "describe": "<p>Which JavaScript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?</p><p></p>",
1369
+ "answerOptions": [
1370
+ {
1371
+ "describe": "<p>JSON.serialize and JSON.deserialize</p>",
1372
+ "isRight": false
1373
+ },
1374
+ {
1375
+ "describe": "<p>JSON.encode and JSON.decode</p>",
1376
+ "isRight": false
1377
+ },
1378
+ {
1379
+ "describe": "<p>JSON.parse and JSON.deserialize</p>",
1380
+ "isRight": false
1381
+ },
1382
+ {
1383
+ "describe": "<p>JSON.stringify and JSON.parse</p>",
1384
+ "isRight": true
1385
+ }
1386
+ ],
1387
+ "analysis": "<p>The JSON.parse() method parses a string and returns a JavaScript object.</p><p>The JSON.stringify() method converts a JavaScript object or value to a JSON string</p>",
1388
+ "hashCode": 497847359
1389
+ },
1390
+ {
1391
+ "describe": "<p>Refer to the code below:</p><p>01 function myFunction(reassign) {</p><p>02 let x = 1;</p><p>03 var y = 1;</p><p>04</p><p>05 if(reassign) {</p><p>06 let x = 2 ;</p><p>07 var y = 2 ;</p><p>08 console.log(x) ;</p><p>09 console.log(y) ;</p><p>10 }</p><p>11</p><p>12 console.log(x) ;</p><p>13 console.log(y) ;</p><p>14 }</p><p>What is displayed when myFunction (true) is called?</p><p></p>",
1392
+ "answerOptions": [
1393
+ {
1394
+ "describe": "<p>2 2 undefined undefined</p>",
1395
+ "isRight": false
1396
+ },
1397
+ {
1398
+ "describe": "<p>2 2 2 2</p>",
1399
+ "isRight": false
1400
+ },
1401
+ {
1402
+ "describe": "<p>2 2 1 2</p>",
1403
+ "isRight": true
1404
+ },
1405
+ {
1406
+ "describe": "<p>2 2 1 1</p>",
1407
+ "isRight": false
1408
+ }
1409
+ ],
1410
+ "analysis": "",
1411
+ "hashCode": -1111513407
1412
+ },
1413
+ {
1414
+ "describe": "<p>Which two code snippets show working examples of a recursive function? Choose 2 answers</p><p></p>",
1415
+ "answerOptions": [
1416
+ {
1417
+ "describe": "<p>const factorial = numVar => {</p><p>if (numVar < 0) return ;</p><p>if (numVar === 0) return 1 ;</p><p>return numVar * factorial (numVar - 1);</p><p>}</p>",
1418
+ "isRight": true
1419
+ },
1420
+ {
1421
+ "describe": "<p>let countingDown = function(startNumber) {</p><p>if (startNumber > 0) {</p><p>console.log (startNumber) ;</p><p>return countingDown(startNumber - 1);</p><p>} else {</p><p>return startNumber;</p><p>}</p><p>} ;</p>",
1422
+ "isRight": true
1423
+ },
1424
+ {
1425
+ "describe": "<p>function factorial (numVar) {</p><p>if (numVar < 0) return;</p><p>if (numVar === 0) return 1;</p><p>return numVar - 1;</p><p>}</p>",
1426
+ "isRight": false
1427
+ },
1428
+ {
1429
+ "describe": "<p>const sumToTen = numVar => {</p><p>if (numVar < 0)</p><p>return ;</p><p>return sumToTen(numVar + 1);</p><p>} ;</p>",
1430
+ "isRight": false
1431
+ }
1432
+ ],
1433
+ "analysis": "",
1434
+ "hashCode": 1507102128
1435
+ },
1436
+ {
1437
+ "describe": "<p>Refer to the code below:</p><p>01 x = 3.14 ;</p><p>02</p><p>03 function myFunction( ) {</p><p>04 'use strict' ;</p><p>05 y=x ;</p><p>06 }</p><p>07</p><p>08 z=x ;</p><p>09 myFunction( ) ;</p><p>Considering the implications of 'use strict' on line 04, which three statements describe the execution of the code? Choose 3 answers</p>",
1438
+ "answerOptions": [
1439
+ {
1440
+ "describe": "<p>'use strict' has an effect between line 04 and the end of the file.</p>",
1441
+ "isRight": false
1442
+ },
1443
+ {
1444
+ "describe": "<p>'use strict' has an effect only on line 05.</p>",
1445
+ "isRight": true
1446
+ },
1447
+ {
1448
+ "describe": "<p>z is equal to 3.14.</p>",
1449
+ "isRight": true
1450
+ },
1451
+ {
1452
+ "describe": "<p>'use strict' is hoisted, so it has an effect on all lines.</p>",
1453
+ "isRight": false
1454
+ },
1455
+ {
1456
+ "describe": "<p>Line 05 throws an error.</p>",
1457
+ "isRight": true
1458
+ }
1459
+ ],
1460
+ "analysis": "<p>To invoke strict mode for an entire script, put the exact statement \"use strict\"; (or 'use strict';) before any other statements.</p><p>to invoke strict mode for a function, put the exact statement \"use strict\"; (or 'use strict';) in the function's body before any other statements.</p><p>check strict mode</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode</p>",
1461
+ "hashCode": -1960355230
1462
+ },
1463
+ {
1464
+ "describe": "<p>A developer wants to create an object from a function in the browser using the code below.</p><p>01 function Monster( ){ this.name = 'hello' };</p><p>02 const m = Monster( );</p><p>What happens due to the lack of the new keyword on line 02?</p><p></p>",
1465
+ "answerOptions": [
1466
+ {
1467
+ "describe": "<p>The m variable is assigned the correct object but this.name remains undefined.</p>",
1468
+ "isRight": false
1469
+ },
1470
+ {
1471
+ "describe": "<p>window.name is assigned to 'hello' and the variable m remains undefined.</p>",
1472
+ "isRight": true
1473
+ },
1474
+ {
1475
+ "describe": "<p>window.m is assigned the correct object.</p>",
1476
+ "isRight": false
1477
+ },
1478
+ {
1479
+ "describe": "<p>The m variable is assigned the correct object.</p>",
1480
+ "isRight": false
1481
+ }
1482
+ ],
1483
+ "analysis": "<p>without new, it is like calling Monster() function, and at this time, this points to windows object. So it is like assigning a name attribtue to the window object</p>",
1484
+ "hashCode": 834722722
1485
+ },
1486
+ {
1487
+ "describe": "<p>Refer to the code below:</p><p>01 function Person( ) {</p><p>02 this . firstName = 'John' ;</p><p>03 }</p><p>04</p><p>05 Person. prototype = {</p><p>06 job: x => 'Developer '</p><p>07 } ;</p><p>08</p><p>09 const myFather = new Person( ) ;</p><p>10 const result = myFather . firstName + ' ' + myFather. job( ) ;</p><p>What is the value of result after line 10 executes?</p><p></p>",
1488
+ "answerOptions": [
1489
+ {
1490
+ "describe": "<p>John Developer</p>",
1491
+ "isRight": true
1492
+ },
1493
+ {
1494
+ "describe": "<p>Error: myFather.job is not a function</p>",
1495
+ "isRight": false
1496
+ },
1497
+ {
1498
+ "describe": "<p>undefined Developer</p>",
1499
+ "isRight": false
1500
+ },
1501
+ {
1502
+ "describe": "<p>John undefined</p>",
1503
+ "isRight": false
1504
+ }
1505
+ ],
1506
+ "analysis": "",
1507
+ "hashCode": -379898079
1508
+ },
1509
+ {
1510
+ "describe": "<p>Refer to the following code block:</p><p>01 let array= [1, 2, 3, 4, 5, 6,7, 8, 9, 10, 11];</p><p>02 let output = 0 ;</p><p>03</p><p>04 for (let num of array) {</p><p>05 if (output > 10) {</p><p>06 break;</p><p>07 }</p><p>08 if (num % 2 == 0) {</p><p>09 continue;</p><p>10 }</p><p>11 output += num;</p><p>12 }</p><p>What is the value of output after the code executes?</p><p></p>",
1511
+ "answerOptions": [
1512
+ {
1513
+ "describe": "<p>25</p>",
1514
+ "isRight": false
1515
+ },
1516
+ {
1517
+ "describe": "<p>36</p>",
1518
+ "isRight": false
1519
+ },
1520
+ {
1521
+ "describe": "<p>11</p>",
1522
+ "isRight": false
1523
+ },
1524
+ {
1525
+ "describe": "<p>16</p>",
1526
+ "isRight": true
1527
+ }
1528
+ ],
1529
+ "analysis": "<p>break will stop current loop, continue will skip to next looping item</p>",
1530
+ "hashCode": 408011449
1531
+ },
1532
+ {
1533
+ "describe": "<p>Refer to the following code:</p><p>01 class Vehicle {</p><p>02 constructor(plate) {</p><p>03 this. plate = plate;</p><p>04 }</p><p>05 }</p><p>06</p><p>07 class Truck extends Vehicle {</p><p>08 constructor(plate, weight) {</p><p>09 //Missing code</p><p>10 this.weight = weight;</p><p>11 }</p><p>12 displayWieght( ) {</p><p>13 console. log(`The truck ${this.plate} has a weight of ${this.weight} 1b. `);</p><p>14 }</p><p>15 }</p><p>16</p><p>17 let myTruck = new Truck('123AB', 5000);</p><p>18 myTruck. displayweight ( ) ;</p><p>Which statement should be added to line 09 for the code to display 'The truck 123AB has a weight of 5000 lb.'?</p><p></p>",
1534
+ "answerOptions": [
1535
+ {
1536
+ "describe": "<p>this.plate = plate;</p>",
1537
+ "isRight": false
1538
+ },
1539
+ {
1540
+ "describe": "<p>super (plate);</p>",
1541
+ "isRight": true
1542
+ },
1543
+ {
1544
+ "describe": "<p>Vehicle.plate = plate;</p>",
1545
+ "isRight": false
1546
+ },
1547
+ {
1548
+ "describe": "<p>super.plate = plate;</p>",
1549
+ "isRight": false
1550
+ }
1551
+ ],
1552
+ "analysis": "",
1553
+ "hashCode": 1143599746
1554
+ },
1555
+ {
1556
+ "describe": "<p>A developer has the following array of hourly wages:</p><p>let arr = [8.5, 9.75, 11.25, 7.75, 13.25];</p><p>For workers making less than $10 an hour, their rate should be multiplied by 1.25 and returned in a new array. How should the developer implement the request?</p><p></p>",
1557
+ "answerOptions": [
1558
+ {
1559
+ "describe": "<p>let arr1 = arr.filter((val) => val < 10).map((num) => num * 1.25);</p>",
1560
+ "isRight": false
1561
+ },
1562
+ {
1563
+ "describe": "<p>let arr1 = arr.mapArray((val) => { val < 10} ).map((num) => {num * 1.25} );</p>",
1564
+ "isRight": false
1565
+ },
1566
+ {
1567
+ "describe": "<p>let arr1 = arr.map( (num) => { return num * 1.25 } ).filter( (val) =>{ return val < 10} );</p>",
1568
+ "isRight": false
1569
+ },
1570
+ {
1571
+ "describe": "<p>let arr1 = arr.filterBy( ( val) => val < 10). mapBy ((num) => num * 1.25);</p>",
1572
+ "isRight": true
1573
+ }
1574
+ ],
1575
+ "analysis": "",
1576
+ "hashCode": 97594328
1577
+ },
1578
+ {
1579
+ "describe": "<p>Refer to the following code:</p><p>01 let obj = {</p><p>02 foo: 1,</p><p>03 bar: 2</p><p>04 }</p><p>05 let output = [ ];</p><p>06</p><p>07 for (let something of obj) {</p><p>08 output.push(something);</p><p>09 }</p><p>10</p><p>11 console.log(output);</p><p>what is the value of output on line 11?</p><p></p>",
1580
+ "answerOptions": [
1581
+ {
1582
+ "describe": "<p>[1, 2]</p>",
1583
+ "isRight": false
1584
+ },
1585
+ {
1586
+ "describe": "<p>[\"foo\", \"bar\"]</p>",
1587
+ "isRight": false
1588
+ },
1589
+ {
1590
+ "describe": "<p>[\"foo:1\", \"bar:2\"]</p>",
1591
+ "isRight": false
1592
+ },
1593
+ {
1594
+ "describe": "<p>An error will occur due to the incorrect usage of the for…of statement on line 07.</p>",
1595
+ "isRight": true
1596
+ }
1597
+ ],
1598
+ "analysis": "",
1599
+ "hashCode": 371479167
1600
+ },
1601
+ {
1602
+ "describe": "<p>A developer creates a class that represents a news story based on the requirements that a Story should have a body, author, and view count. The code is shown below:</p><p>01 class Story {</p><p>02 //Insert code here</p><p>03 this.body = body;</p><p>04 this.author = author;</p><p>05 this.viewCount = viewCount;</p><p>06 }</p><p>07 }</p><p>Which statement should be inserted in the placeholder on line 02 to allow for a variable to be set to a new instance of a Story with the three attributes correctly populated?</p><p></p>",
1603
+ "answerOptions": [
1604
+ {
1605
+ "describe": "<p>function Story (body, author, viewCount) {</p>",
1606
+ "isRight": false
1607
+ },
1608
+ {
1609
+ "describe": "<p>super (body, author, viewCount) {</p>",
1610
+ "isRight": false
1611
+ },
1612
+ {
1613
+ "describe": "<p>constructor (body, author, viewCount) {</p>",
1614
+ "isRight": true
1615
+ },
1616
+ {
1617
+ "describe": "<p>constructor ( ) {</p>",
1618
+ "isRight": false
1619
+ }
1620
+ ],
1621
+ "analysis": "",
1622
+ "hashCode": 1040595420
1623
+ },
1624
+ {
1625
+ "describe": "<p>Refer to the following code block:</p><p>01 class Animal {</p><p>02 constructor(name) {</p><p>03 this.name = name;</p><p>04 }</p><p>05</p><p>06 makeSound() {</p><p>07 console.log( '${this.name} is making a sound. ');</p><p>08 }</p><p>09 }</p><p>10</p><p>11 class Dog extends Animal {</p><p>12 constructor(name) {</p><p>13 super(name);</p><p>14 this.name = name;</p><p>15 }</p><p>16 makeSound( ) {</p><p>17 console.log('${this.name} is barking.');</p><p>18 }</p><p>19 }</p><p>20</p><p>21 let myDog = new Dog('Puppy');</p><p>22 myDog.makeSound();</p><p>What is the console output?</p><p></p>",
1626
+ "answerOptions": [
1627
+ {
1628
+ "describe": "<p>> Undefined</p>",
1629
+ "isRight": false
1630
+ },
1631
+ {
1632
+ "describe": "<p>> Puppy is making a sound.</p>",
1633
+ "isRight": false
1634
+ },
1635
+ {
1636
+ "describe": "<p>> Puppy is barking.</p>",
1637
+ "isRight": true
1638
+ },
1639
+ {
1640
+ "describe": "<p>> Uncaught ReferenceError</p>",
1641
+ "isRight": false
1642
+ }
1643
+ ],
1644
+ "analysis": "",
1645
+ "hashCode": -137451209
1646
+ },
1647
+ {
1648
+ "describe": "<p>Which statement parses successfully?</p><p></p>",
1649
+ "answerOptions": [
1650
+ {
1651
+ "describe": "<p>JSON.parse('foo');</p>",
1652
+ "isRight": false
1653
+ },
1654
+ {
1655
+ "describe": "<p>JSON.parse(\" 'foo' \");</p>",
1656
+ "isRight": false
1657
+ },
1658
+ {
1659
+ "describe": "<p>JSON.parse(' \"foo\" ');</p>",
1660
+ "isRight": false
1661
+ },
1662
+ {
1663
+ "describe": "<p>JSON.parse(\"foo\");</p>",
1664
+ "isRight": true
1665
+ }
1666
+ ],
1667
+ "analysis": "",
1668
+ "hashCode": -1183134338
1669
+ },
1670
+ {
1671
+ "describe": "<p>A developer writes the code below to calculate the factorial of a given number.</p><p>01 function sum(number) {</p><p>02 return number + sum(number -1);</p><p>03 }</p><p>04 sum(3);</p><p>What is the result of executing line 04?</p><p></p>",
1672
+ "answerOptions": [
1673
+ {
1674
+ "describe": "<p>0</p>",
1675
+ "isRight": false
1676
+ },
1677
+ {
1678
+ "describe": "<p>6</p>",
1679
+ "isRight": false
1680
+ },
1681
+ {
1682
+ "describe": "<p>Error</p>",
1683
+ "isRight": true
1684
+ },
1685
+ {
1686
+ "describe": "<p>-Infinity</p>",
1687
+ "isRight": false
1688
+ }
1689
+ ],
1690
+ "analysis": "",
1691
+ "hashCode": 181674848
1692
+ },
1693
+ {
1694
+ "describe": "<p>myArray, can have one level, two levels, or more levels. Which statement flattens myArray when it can be arbitrarily nested?</p><p></p>",
1695
+ "answerOptions": [
1696
+ {
1697
+ "describe": "<p>myArray.reduce((prev, curr) => prev.concat(curr), [ ]);</p>",
1698
+ "isRight": false
1699
+ },
1700
+ {
1701
+ "describe": "<p>myArray.join(\",\").split(\".\");</p>",
1702
+ "isRight": false
1703
+ },
1704
+ {
1705
+ "describe": "<p>myArray.flat(Infinity);</p>",
1706
+ "isRight": true
1707
+ },
1708
+ {
1709
+ "describe": "<p>[ ].concat(…myArray);</p>",
1710
+ "isRight": false
1711
+ }
1712
+ ],
1713
+ "analysis": "",
1714
+ "hashCode": -933703618
1715
+ },
1716
+ {
1717
+ "describe": "<p>Refer to the code below:</p><p>01 function Person(firstName, lastName, eyeColor) {</p><p>02 this.firstName = firstName;</p><p>03 this.lastName = lastName;</p><p>04 this.eyeColor = eyeColor;</p><p>05 }</p><p>06 Person.job = 'Developer';</p><p>07</p><p>08 const myFather = new Person('John', 'Doe');</p><p>09 console.log(myFather.job);</p><p>What is the output after the code executes?</p><p></p>",
1718
+ "answerOptions": [
1719
+ {
1720
+ "describe": "<p>ReferenceError: eyeColor is not defined</p>",
1721
+ "isRight": false
1722
+ },
1723
+ {
1724
+ "describe": "<p>TypeError: invalid assignment to const variable Person</p>",
1725
+ "isRight": false
1726
+ },
1727
+ {
1728
+ "describe": "<p>undefined</p>",
1729
+ "isRight": true
1730
+ },
1731
+ {
1732
+ "describe": "<p>Developer</p>",
1733
+ "isRight": false
1734
+ }
1735
+ ],
1736
+ "analysis": "",
1737
+ "hashCode": 162330172
1738
+ },
1739
+ {
1740
+ "describe": "<p>Refer to the code below:</p><p>flag( ) ;</p><p>function flag( ) {</p><p>console.log('flag') ;</p><p>}</p><p>const anotherFlag = ( ) => {</p><p>console.log( 'another flag') ;</p><p>}</p><p>anotherFlag( );</p><p>What is result of the code block?</p><p></p>",
1741
+ "answerOptions": [
1742
+ {
1743
+ "describe": "<p>An error is thrown.</p>",
1744
+ "isRight": false
1745
+ },
1746
+ {
1747
+ "describe": "<p>The console logs only 'flag'.</p>",
1748
+ "isRight": false
1749
+ },
1750
+ {
1751
+ "describe": "<p>The console logs 'flag' and 'another flag'.</p>",
1752
+ "isRight": true
1753
+ },
1754
+ {
1755
+ "describe": "<p>The console logs 'flag' and then an error is thrown.</p>",
1756
+ "isRight": false
1757
+ }
1758
+ ],
1759
+ "analysis": "",
1760
+ "hashCode": 1425998350
1761
+ },
1762
+ {
1763
+ "describe": "<p>A developer copied a JavaScript object:</p><p>01 function Person() {</p><p>02 this.firstName = \"John\";</p><p>03 this.lastName = \"Doe\";</p><p>04 this.name = () => '${this.firstName}, ${this.lastName}';</p><p>05 }</p><p>06</p><p>07 const john = new Person();</p><p>08 const dan = Object.assign(john);</p><p>09 dan.firstName = 'Dan';</p><p>How does the developer access dan's firstName.lastName? Choose 2 answers</p><p></p>",
1764
+ "answerOptions": [
1765
+ {
1766
+ "describe": "<p>dan.name</p>",
1767
+ "isRight": false
1768
+ },
1769
+ {
1770
+ "describe": "<p>dan.name()</p>",
1771
+ "isRight": true
1772
+ },
1773
+ {
1774
+ "describe": "<p>dan.firstName + dan.lastName</p>",
1775
+ "isRight": true
1776
+ },
1777
+ {
1778
+ "describe": "<p>dan.firstName() + dan.lastName()</p>",
1779
+ "isRight": false
1780
+ }
1781
+ ],
1782
+ "analysis": "",
1783
+ "hashCode": -431743692
1784
+ }
1785
+ ],
1786
+ "hashCode": 148683738
1787
+ }