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

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,547 @@
1
+ {
2
+ "title": "[JS]第五章 异步编程",
3
+ "category": "JS-1",
4
+ "questions": [
5
+ {
6
+ "describe": "<p>Given the code below:</p><p>const delay = async delay => {</p><p>return new Promise ( ( resolve, reject ) =></p><p>{</p><p>setTimeout ( resolve, delay );</p><p>});</p><p>};</p><p>const callDelay = async ( ) => {</p><p>const yup = await delay(1000);</p><p>console.log(1);</p><p>};</p><p>console.log(2);</p><p>callDelay( );</p><p>console.log(3);</p><p>What is logged to the console?</p>",
7
+ "answerOptions": [
8
+ {
9
+ "describe": "<p>1 2 3</p>",
10
+ "isRight": false
11
+ },
12
+ {
13
+ "describe": "<p>1 3 2</p>",
14
+ "isRight": false
15
+ },
16
+ {
17
+ "describe": "<p>2 1 3</p>",
18
+ "isRight": false
19
+ },
20
+ {
21
+ "describe": "<p>2 3 1</p>",
22
+ "isRight": true
23
+ }
24
+ ],
25
+ "analysis": "<p>callDelay( ); will be executed after 3 printed.</p>",
26
+ "hashCode": 2050585304
27
+ },
28
+ {
29
+ "describe": "<p>Refer to the code below:</p><p>01 let requestPromise = client.getRequest;</p><p>02</p><p>03 requestPromise ( ) . then( (response) => {</p><p>04 handleResponse (response) ;</p><p>05 });</p><p>A developer uses a client that makes a GET request that uses a Promise to handle the request.getRequest returns a Promise.Which code modification can the developer make to gracefully handle an error?</p>",
30
+ "answerOptions": [
31
+ {
32
+ "describe": "<p>01 let requestPromise = client. getRequest;</p><p>02</p><p>03 try {</p><p>04 requestPromise( ) .then((response) => {</p><p>05 handleResponse (response) ;</p><p>06 }) .then((error) => {</p><p>07 throw new Error(error.name);</p><p>08 });</p><p>09 } catch(error) {</p><p>10 handleError(error);</p><p>11 }</p>",
33
+ "isRight": false
34
+ },
35
+ {
36
+ "describe": "<p>01 let requestPromise = client. getRequest;</p><p>02</p><p>03 try {</p><p>04 requestPromise( ) .then((response) => {</p><p>05 handleResponse (response) ;</p><p>06 }) ;</p><p>07 } catch(error) {</p><p>08 handleError(error);</p><p>09 }</p>",
37
+ "isRight": false
38
+ },
39
+ {
40
+ "describe": "<p>01 let requestPromise = client. getRequest;</p><p>02</p><p>03 requestPromise( ) .then((response) => {</p><p>04 handleResponse (response) ;</p><p>05 }) .catch((error) => {</p><p>06 handleError(error);</p><p>07 });</p>",
41
+ "isRight": true
42
+ },
43
+ {
44
+ "describe": "<p>01 let requestPromise = client. getRequest;</p><p>02</p><p>03 requestPromise( ) .then((response) => {</p><p>04 handleResponse (response) ;</p><p>05 }) .finally((error) => {</p><p>06 handleError(error);</p><p>07 });</p>",
45
+ "isRight": false
46
+ }
47
+ ],
48
+ "analysis": "<p>check Promise.catch();</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch</p>",
49
+ "hashCode": -1190035552
50
+ },
51
+ {
52
+ "describe": "<p>Refer to the code below:</p><p>01 const exec = (item, delay) =></p><p>02 new Promise (resolve => setTimeout(( ) => resolve(item), delay)) ;</p><p>03</p><p>04 async function runParallel( ) {</p><p>05 const [result1, result2, result3] = await Promise.all(</p><p>06 [exec('x', '100'), exec('y', '500'), exec('z' ,'100') ]</p><p>07 );</p><p>08 return `parallel is done: ${result1}$ {}result2}${result3}` ;</p><p>09 }</p><p>Which two statements correctly execute the runParallel ( ) function? Choose 2 answers</p>",
53
+ "answerOptions": [
54
+ {
55
+ "describe": "<p>runParallel( ) .then (function(data) {</p><p>return data;</p><p>});</p>",
56
+ "isRight": true
57
+ },
58
+ {
59
+ "describe": "<p>runParallel( ) .done (function (data) {</p><p>return data;</p><p>});</p>",
60
+ "isRight": false
61
+ },
62
+ {
63
+ "describe": "<p>async runParallel( ) .then(data);</p>",
64
+ "isRight": false
65
+ },
66
+ {
67
+ "describe": "<p>runParallel( ) .then(data);</p>",
68
+ "isRight": true
69
+ }
70
+ ],
71
+ "analysis": "",
72
+ "hashCode": -2045125581
73
+ },
74
+ {
75
+ "describe": "<p>Given the following code:</p><p>01 counter = 0;</p><p>02 const logCounter = ( ) => {</p><p>03 console.log (counter) ;</p><p>04 };</p><p>05 logCounter( ) ;</p><p>06 setTimeout (logCounter, 1100) ;</p><p>07 setInterval(( ) => {</p><p>08 counter++ ;</p><p>09 logCounter( ) ;</p><p>10 }, 1000) ;</p><p>What is logged by the first four log statements?</p>",
76
+ "answerOptions": [
77
+ {
78
+ "describe": "<p>0 0 1 2</p>",
79
+ "isRight": false
80
+ },
81
+ {
82
+ "describe": "<p>0 1 2 3</p>",
83
+ "isRight": false
84
+ },
85
+ {
86
+ "describe": "<p>0 1 1 2</p>",
87
+ "isRight": true
88
+ },
89
+ {
90
+ "describe": "<p>0 1 2 2</p>",
91
+ "isRight": false
92
+ }
93
+ ],
94
+ "analysis": "",
95
+ "hashCode": 1786270805
96
+ },
97
+ {
98
+ "describe": "<p>Which is not the valid state in Promise?</p>",
99
+ "answerOptions": [
100
+ {
101
+ "describe": "<p>Resolved</p>",
102
+ "isRight": true
103
+ },
104
+ {
105
+ "describe": "<p>Pending</p>",
106
+ "isRight": false
107
+ },
108
+ {
109
+ "describe": "<p>Rejected</p>",
110
+ "isRight": false
111
+ },
112
+ {
113
+ "describe": "<p>Fulfilled</p>",
114
+ "isRight": false
115
+ }
116
+ ],
117
+ "analysis": "<p>A Promise can result in one of these states:</p><p>Pending: initial state, neither fulfilled nor rejected.</p><p>Fulfilled: meaning that the operation completed successfully.</p><p>Rejected: meaning that the operation failed.</p><p>Resolved is not the state, it is more like fate. A promise will have two possible mutually exclusive fates: resolved and unresolved.</p><p>A promise whose fate is resolved can result in any of the three states: pending, fulfilled, and rejected.</p><p>A promise whose fate is unresolved is necessarily pending.</p>",
118
+ "hashCode": -1641176419
119
+ },
120
+ {
121
+ "describe": "<p>Which of the following is not a standard function name when using promises?</p>",
122
+ "answerOptions": [
123
+ {
124
+ "describe": "<p>try</p>",
125
+ "isRight": true
126
+ },
127
+ {
128
+ "describe": "<p>finally</p>",
129
+ "isRight": false
130
+ },
131
+ {
132
+ "describe": "<p>then</p>",
133
+ "isRight": false
134
+ },
135
+ {
136
+ "describe": "<p>catch</p>",
137
+ "isRight": false
138
+ }
139
+ ],
140
+ "analysis": "<p>Try is not a function name when using Promise. Check out the reference link for a list of supported functions.</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise</p>",
141
+ "hashCode": -956349193
142
+ },
143
+ {
144
+ "describe": "<p>Which of the following code snippets will show alert box? Choose 3 answers.</p>",
145
+ "answerOptions": [
146
+ {
147
+ "describe": "<p>new Promise((resolve, reject) => {</p><p>throw new Error(\"Whoops!\");</p><p>}).catch(alert);</p>",
148
+ "isRight": true
149
+ },
150
+ {
151
+ "describe": "<p>new Promise(function(resolve, reject) {</p><p>setTimeout(() => {</p><p>throw new Error(\"Whoops!\");</p><p>}, 1000);</p><p>}).catch(alert);</p>",
152
+ "isRight": false
153
+ },
154
+ {
155
+ "describe": "<p>new Promise((resolve, reject) => {</p><p>resolve(\"ok\");</p><p>}).then((result) => {</p><p>throw new Error(\"Whoops!\");</p><p>}).catch(alert);</p>",
156
+ "isRight": true
157
+ },
158
+ {
159
+ "describe": "<p>new Promise((resolve, reject) => {</p><p>reject(new Error(\"Whoops!\"));</p><p>}).catch(alert);</p>",
160
+ "isRight": true
161
+ }
162
+ ],
163
+ "analysis": "<p>When an exception happens, it gets caught and treated as a rejection.</p><p>new Promise(function(resolve, reject) {</p><p>setTimeout(() => {</p><p>throw new Error(\"Whoops!\");</p><p>}, 1000);</p><p>}).catch(alert); // will not catch error</p><p>Copy</p><p>The code snippet above will not show alert box even though the error is thrown in within Promise code block. Reason being, the error is generated not while the executor is running, but later in another task. Hence, the promise cannot catch the error.</p>",
164
+ "hashCode": -106788969
165
+ },
166
+ {
167
+ "describe": "<p>const getId = new Promise((resolve, reject) => {</p><p>setTimeout(() => resolve(15), 1500);</p><p>});</p><p>const getBook = bookId => new Promise((resolve, reject) => {</p><p>setTimeout(() => resolve('${bookId}:JavaScript Algorithms'), 1500);</p><p>});</p><p>getId.then(id => getBook(id)).then(data => data);</p><p>What is the correct code to replace the last line with an async/await function?</p>",
168
+ "answerOptions": [
169
+ {
170
+ "describe": "<p>async function getBookInfo() {</p><p>const Id = await getId;</p><p>const result = await getBook(id);</p><p>}</p><p>await getBookInfo();</p>",
171
+ "isRight": false
172
+ },
173
+ {
174
+ "describe": "<p>async function getBookInfo() {</p><p>const Id = getId;</p><p>const result = getBook(id);</p><p>}</p><p>await getBookInfo();</p>",
175
+ "isRight": false
176
+ },
177
+ {
178
+ "describe": "<p>await function getBookInfo() {</p><p>const Id = getId;</p><p>const result = getBook(id);</p><p>}</p><p>async getBookInfo();</p>",
179
+ "isRight": false
180
+ },
181
+ {
182
+ "describe": "<p>async function getBookInfo() {</p><p>const Id = await getId;</p><p>const result = await getBook(id);</p><p>}</p><p>getBookInfo();</p>",
183
+ "isRight": true
184
+ }
185
+ ],
186
+ "analysis": "<p>The correct use of await with an async function is the following codeasync function getBookInfo() {</p><p>const Id = await getId;</p><p>const result = await getBook(id);</p><p>}</p><p>getBookInfo();</p><p>The await expression must be used inside an async function.</p>",
187
+ "hashCode": 1465758323
188
+ },
189
+ {
190
+ "describe": "<p>Give the code as below:</p><p>let promise = new Promise(function(resolve, reject) {</p><p>resolve(1);</p><p>setTimeout(() => resolve(2), 1000);</p><p>setTimeout(() => resolve(3), 2000);</p><p>});</p><p>promise.then((res) => console.log(res));</p><p>What would be the output of this code?</p>",
191
+ "answerOptions": [
192
+ {
193
+ "describe": "<p>1</p>",
194
+ "isRight": true
195
+ },
196
+ {
197
+ "describe": "<p>3</p>",
198
+ "isRight": false
199
+ },
200
+ {
201
+ "describe": "<p>2</p>",
202
+ "isRight": false
203
+ },
204
+ {
205
+ "describe": "<p>undefined</p>",
206
+ "isRight": false
207
+ }
208
+ ],
209
+ "analysis": "<p>The correct answer is 1. The second and third calls to resolve are ignored because only the first call of reject/resolve is taken into account. Further calls are all ignored.</p>",
210
+ "hashCode": -1047881134
211
+ },
212
+ {
213
+ "describe": "<p>Refer to this code:</p><p>const p1 = new Promise((resolve, reject) => {</p><p>setTimeout(() => {</p><p>resolve('P1 Resolved');</p><p>}, 1500);</p><p>});</p><p>const p2 = (data) => new Promise((resolve, reject) => {</p><p>setTimeout(() => resolve('${data}, P2 Resolved'), 1500, data);</p><p>});</p><p>Which of the following correctly execute p1 and p2? Choose 2 answers.</p><p></p>",
214
+ "answerOptions": [
215
+ {
216
+ "describe": "<p>p1</p><p>.then((data) => p2(data))</p><p>.then(result => result);</p>",
217
+ "isRight": true
218
+ },
219
+ {
220
+ "describe": "<p>p1().then(function() {</p><p>p2().then(function(result) {</p><p>return result;</p><p>});</p><p>});</p>",
221
+ "isRight": false
222
+ },
223
+ {
224
+ "describe": "<p>async function getResult() {</p><p>const data = await p1;</p><p>return await p2(data);</p><p>}</p><p>getResult();</p>",
225
+ "isRight": true
226
+ },
227
+ {
228
+ "describe": "<p>async function getResult() {</p><p>const data = p1;</p><p>const result = p2(data);</p><p>}</p><p>await getResult();</p>",
229
+ "isRight": false
230
+ }
231
+ ],
232
+ "analysis": "<p>p1</p><p>.then((data) => p2(data))</p><p>.then(result => result);</p><p>This is correct. The method promise.then() is used to associate further action with a promise that becomes settled.</p><p>async function getResult() {</p><p>const data = await p1;</p><p>return await p2(data);</p><p>}</p><p>getResult();</p><p>This is correct. Using await inside the function causes both to execute.</p><p>p1().then(function() {</p><p>p2().then(function(result) {</p><p>return result;</p><p>});</p><p>});</p><p>This is incorrect. The syntax is wrong for calling p1 and p2.</p><p>async function getResult() {</p><p>const data = p1;</p><p>const result = p2(data);</p><p>}</p><p>await getResult();</p><p>This is incorrect. The await is outside the function calling the data.</p>",
233
+ "hashCode": 588378204
234
+ },
235
+ {
236
+ "describe": "<p>Given the following code, which one would be the correct order when executed?</p><p>setTimeout(() => console.log(\"timeout\"));</p><p>Promise.resolve().then(() => console.log(\"promise\"));</p><p>console.log(\"code\");</p><p></p>",
237
+ "answerOptions": [
238
+ {
239
+ "describe": "<p>timeout — promise — code</p>",
240
+ "isRight": false
241
+ },
242
+ {
243
+ "describe": "<p>code — timeout — promise</p>",
244
+ "isRight": false
245
+ },
246
+ {
247
+ "describe": "<p>code — promise — timeout</p>",
248
+ "isRight": true
249
+ },
250
+ {
251
+ "describe": "<p>timeout — code — promise</p>",
252
+ "isRight": false
253
+ }
254
+ ],
255
+ "analysis": "<p>The correct order will be:</p><p>code</p><p>promise</p><p>timeout</p><p>Code shows first, because it’s a regular synchronous call. Promise shows second, because .then passes through the microtask queue, and runs after the current code. Timeout shows last, because it’s a macrotask.</p>",
256
+ "hashCode": 357264864
257
+ },
258
+ {
259
+ "describe": "<p>Which statement accurately describes an aspect of promises?</p><p></p>",
260
+ "answerOptions": [
261
+ {
262
+ "describe": "<p>then( ) cannot be added after a catch.</p>",
263
+ "isRight": false
264
+ },
265
+ {
266
+ "describe": "<p>Arguments for the callback function passed to . then( ) are optional.</p>",
267
+ "isRight": true
268
+ },
269
+ {
270
+ "describe": "<p>In a · then( ) function, returning results is not necessary since callbacks will catch the result of a previous promise.</p>",
271
+ "isRight": false
272
+ },
273
+ {
274
+ "describe": "<p>then( ) manipulates and returns the original promise.</p>",
275
+ "isRight": false
276
+ }
277
+ ],
278
+ "analysis": "<p>The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then</p><p>for example:</p><p>return p.catch(...).then(...);</p><p>If a promise return a normal value or a promise that eventually resolves from the .catch() handler (thus \"handling\" the error), then the promise chain switches to the resolved state and the .then() handler after the .catch() will be called.</p>",
279
+ "hashCode": 1150606644
280
+ },
281
+ {
282
+ "describe": "<p>Which three statements are true about promises? Choose 3 answers</p><p>A The executor of a new Promise runs automatically.</p><p>B A p</p>",
283
+ "answerOptions": [
284
+ {
285
+ "describe": "<p>promise has a . then( ) method.</p><p>C A settled promise can become resolved.</p><p>D A pending promise can become fulfilled, settled, or rejected.</p>",
286
+ "isRight": true
287
+ }
288
+ ],
289
+ "analysis": "<p>A Promise is in one of these states:</p><p>pending: initial state, neither fulfilled nor rejected.</p><p>fulfilled: meaning that the operation was completed successfully.</p><p>rejected: meaning that the operation failed.</p>",
290
+ "hashCode": 1765038670
291
+ },
292
+ {
293
+ "describe": "<p>A developer is wondering whether to use, Promise.then or Promise.catch, especially when a promise throws an error.Which two promises are rejected? Choose 2 answers</p><p></p>",
294
+ "answerOptions": [
295
+ {
296
+ "describe": "<p>Promise.reject('Cool error here').catch(error => console. error(error));</p>",
297
+ "isRight": true
298
+ },
299
+ {
300
+ "describe": "<p>Promise.reject('Cool error here').then(error => console. error(error));</p>",
301
+ "isRight": false
302
+ },
303
+ {
304
+ "describe": "<p>new Promise((resolve, reject) => {throw 'Cool error here'}). catch(error=> console.error(error));</p>",
305
+ "isRight": true
306
+ },
307
+ {
308
+ "describe": "<p>new Promise(( ) => {throw 'Cool error here'}).then((null, error => console.error(error)));</p>",
309
+ "isRight": false
310
+ }
311
+ ],
312
+ "analysis": "<p>use catch block to handle the rejected promise and error</p>",
313
+ "hashCode": -1763880331
314
+ },
315
+ {
316
+ "describe": "<p>Refer to the code below:</p><p>01 console. log('start') ;</p><p>02 Promise. resolve('Success') . then (function (value) {</p><p>03 console. log(' success') ;</p><p>04 });</p><p>05 console.log('End') ;</p><p>What is the output after the code executes successfully?</p><p></p>",
317
+ "answerOptions": [
318
+ {
319
+ "describe": "<p>End Start Success</p>",
320
+ "isRight": false
321
+ },
322
+ {
323
+ "describe": "<p>Start Success End</p>",
324
+ "isRight": false
325
+ },
326
+ {
327
+ "describe": "<p>Success Start End</p>",
328
+ "isRight": false
329
+ },
330
+ {
331
+ "describe": "<p>Start End Success</p>",
332
+ "isRight": true
333
+ }
334
+ ],
335
+ "analysis": "",
336
+ "hashCode": 1594305024
337
+ },
338
+ {
339
+ "describe": "<p>Refer to the code below:</p><p>01 let sayHello = ( ) => {</p><p>02 console. log('Hello, World!') ;</p><p>03 } ;</p><p>Which code executes sayHello once, two minutes from now?</p><p></p>",
340
+ "answerOptions": [
341
+ {
342
+ "describe": "<p>setInterval(sayHello, 120000) ;</p>",
343
+ "isRight": false
344
+ },
345
+ {
346
+ "describe": "<p>delay(sayHello, 120000) ;</p>",
347
+ "isRight": false
348
+ },
349
+ {
350
+ "describe": "<p>setTimeout(sayHello( ), 120000) ;</p>",
351
+ "isRight": false
352
+ },
353
+ {
354
+ "describe": "<p>setTimeout(sayHello, 120000) ;</p>",
355
+ "isRight": true
356
+ }
357
+ ],
358
+ "analysis": "",
359
+ "hashCode": -1522893912
360
+ },
361
+ {
362
+ "describe": "<p>Refer to the code below:</p><p>01 new Promise((resolve, reject) => {</p><p>02 const fraction = Math. random( ) ;</p><p>03 if (fraction > 0.5) reject( 'fraction > 0.5, ' + fraction) ;</p><p>04 resolve(fraction) ;</p><p>05 })</p><p>06 .then(( ) => console.log( 'resolved' ))</p><p>07 .catch((error) => console. error(error))</p><p>08 .finally(( ) => console.log 'when am I called?' )) ;</p><p>When does Promise . finally on line 08 get called?</p><p></p>",
363
+ "answerOptions": [
364
+ {
365
+ "describe": "<p>When rejected</p>",
366
+ "isRight": false
367
+ },
368
+ {
369
+ "describe": "<p>When resolved</p>",
370
+ "isRight": false
371
+ },
372
+ {
373
+ "describe": "<p>When resolved or rejected</p>",
374
+ "isRight": true
375
+ },
376
+ {
377
+ "describe": "<p>When resolved and settled</p>",
378
+ "isRight": false
379
+ }
380
+ ],
381
+ "analysis": "<p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally</p>",
382
+ "hashCode": 1254376068
383
+ },
384
+ {
385
+ "describe": "<p>Which statement accurately describes the behavior of the async/await keywords?</p><p></p>",
386
+ "answerOptions": [
387
+ {
388
+ "describe": "<p>The associated function sometimes returns a promise.</p>",
389
+ "isRight": false
390
+ },
391
+ {
392
+ "describe": "<p>The associated function will always return a promise.</p>",
393
+ "isRight": true
394
+ },
395
+ {
396
+ "describe": "<p>The associated function can only be called via asynchronous methods.</p>",
397
+ "isRight": false
398
+ },
399
+ {
400
+ "describe": "<p>The associated class contains some asynchronous functions.</p>",
401
+ "isRight": false
402
+ }
403
+ ],
404
+ "analysis": "<p>async/ await is used for function, not class</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function</p>",
405
+ "hashCode": 1601200398
406
+ },
407
+ {
408
+ "describe": "<p>Refer to the code below:</p><p>01 let car1 = new Promise((_ , reject) =></p><p>02 setTimeout(reject, 2000, \"Car 1 crashed in\")) ;</p><p>03 let car2 = new Promise (resolve => setTimeout(resolve, 1500, \"Car 2 completed\")) ;</p><p>04 let car3 = new Promise (resolve => setTimeout(resolve, 3000, \"Car 3 completed\")) ;05</p><p>06 Promise. race([car1, car2, car3])</p><p>07 . then (value => {</p><p>08 let result = `${value} the race. `;</p><p>09 }) ;</p><p>10 . catch(err =>{</p><p>11 console.log(\"Race is cancelled.\", err);</p><p>12 }) ;</p><p>What is the value of result when Promise.race executes?</p><p></p>",
409
+ "answerOptions": [
410
+ {
411
+ "describe": "<p>Race is cancelled.</p>",
412
+ "isRight": false
413
+ },
414
+ {
415
+ "describe": "<p>Car 2 completed the race.</p>",
416
+ "isRight": true
417
+ },
418
+ {
419
+ "describe": "<p>Car1 crashed in the race.</p>",
420
+ "isRight": false
421
+ },
422
+ {
423
+ "describe": "<p>Car 3 completed the race.</p>",
424
+ "isRight": false
425
+ }
426
+ ],
427
+ "analysis": "<p>The Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise.</p><p>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race</p>",
428
+ "hashCode": 419951496
429
+ },
430
+ {
431
+ "describe": "<p>Refer to the code below:</p><p>01 let timedFunction = ( ) => {</p><p>02 console. log( 'Timer called.' ) ;</p><p>03 } ;</p><p>04</p><p>05 let timerId = setTimeout (timedFunction, 1000) ;</p><p>Which statement allows a developer to cancel the scheduled timedfunction?</p><p></p>",
432
+ "answerOptions": [
433
+ {
434
+ "describe": "<p>removeTimeout (timedFunction) ;</p>",
435
+ "isRight": false
436
+ },
437
+ {
438
+ "describe": "<p>removeTimeout (timerId) ;</p>",
439
+ "isRight": false
440
+ },
441
+ {
442
+ "describe": "<p>clearTimeout (timerId) ;</p>",
443
+ "isRight": true
444
+ },
445
+ {
446
+ "describe": "<p>clearTimeout (timedFunction) ;</p>",
447
+ "isRight": false
448
+ }
449
+ ],
450
+ "analysis": "",
451
+ "hashCode": 1160036129
452
+ },
453
+ {
454
+ "describe": "<p>A developer has an isDog function that takes one argument,pet. They want to schedule the function to run every minute. What is the correct syntax for scheduling this function?</p><p></p>",
455
+ "answerOptions": [
456
+ {
457
+ "describe": "<p>setTimeout(isDog('cat'), 60000);</p>",
458
+ "isRight": false
459
+ },
460
+ {
461
+ "describe": "<p>setInterval(isDog('cat'), 60000);</p>",
462
+ "isRight": false
463
+ },
464
+ {
465
+ "describe": "<p>setInterval(isDog, 60000, 'cat');</p>",
466
+ "isRight": true
467
+ },
468
+ {
469
+ "describe": "<p>setTimeout(isDog, 60000, 'cat');</p>",
470
+ "isRight": false
471
+ }
472
+ ],
473
+ "analysis": "",
474
+ "hashCode": 1079957535
475
+ },
476
+ {
477
+ "describe": "<p>Refer to the code below:</p><p>01 let sayHello = ( ) => {</p><p>02 console.log('Hello, World!');</p><p>03 };</p><p>Which option executes sayHello once every two minutes?</p><p></p>",
478
+ "answerOptions": [
479
+ {
480
+ "describe": "<p>delay(sayHello, 120000);</p>",
481
+ "isRight": false
482
+ },
483
+ {
484
+ "describe": "<p>setInterval(sayHello, 120000);</p>",
485
+ "isRight": true
486
+ },
487
+ {
488
+ "describe": "<p>setTimeout(sayHello( ), 120000);</p>",
489
+ "isRight": false
490
+ },
491
+ {
492
+ "describe": "<p>setTimeout(sayHello, 120000);</p>",
493
+ "isRight": false
494
+ }
495
+ ],
496
+ "analysis": "",
497
+ "hashCode": -1935794449
498
+ },
499
+ {
500
+ "describe": "<p>Given the code below:</p><p>const delay = async delay => {</p><p>return new Promise ( ( resolve, reject ) =></p><p>{</p><p>console.log(1);</p><p>setTimeout ( resolve, delay );</p><p>});</p><p>};</p><p>const callDelay = async ( ) => {</p><p>console.log(2);</p><p>const yup = await delay(1000);</p><p>console.log(3);</p><p>};</p><p>console.log(4);</p><p>callDelay( );</p><p>console.log(5);</p><p>What is logged to the console?</p><p></p>",
501
+ "answerOptions": [
502
+ {
503
+ "describe": "<p>1 4 2 3 5</p>",
504
+ "isRight": false
505
+ },
506
+ {
507
+ "describe": "<p>4 2 1 3 5</p>",
508
+ "isRight": false
509
+ },
510
+ {
511
+ "describe": "<p>4 2 1 5 3</p>",
512
+ "isRight": true
513
+ },
514
+ {
515
+ "describe": "<p>4 5 1 2 3</p>",
516
+ "isRight": false
517
+ }
518
+ ],
519
+ "analysis": "",
520
+ "hashCode": -333748107
521
+ },
522
+ {
523
+ "describe": "<p>Refer to the code below:</p><p>01 let total = 10;</p><p>02 const interval = setInterval ( ( ) => {</p><p>03 total++;</p><p>04 clearInterval(interval);</p><p>05 total++;</p><p>06 }, 0);</p><p>07 total++;</p><p>08 console.log(total);</p><p>Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?</p><p></p>",
524
+ "answerOptions": [
525
+ {
526
+ "describe": "<p>10</p>",
527
+ "isRight": false
528
+ },
529
+ {
530
+ "describe": "<p>11</p>",
531
+ "isRight": true
532
+ },
533
+ {
534
+ "describe": "<p>12</p>",
535
+ "isRight": false
536
+ },
537
+ {
538
+ "describe": "<p>13</p>",
539
+ "isRight": false
540
+ }
541
+ ],
542
+ "analysis": "",
543
+ "hashCode": -1565203812
544
+ }
545
+ ],
546
+ "hashCode": -819811610
547
+ }