JAVASCRIPT-DEVELOPER-I practice question 12 of 30
Refer to the code below: 01 const exec = (item, delay) =>{ 02 newPromise(resolve => setTimeout( () => resolve(item), delay)), 03 async function…
Full set: 219 questionsDomain Asynchronous Programming
The runParallel function is declared with the async keyword. In JavaScript, an async function always returns a Promise. The standard way to handle the resolved value of a Promise is by using the .then() method. This method takes a callback function as an argument, which is executed once the promise is fulfilled. Both options C and D correctly call the runParallel() function and use the .then() method to process the result. Option D provides an inline anonymous function as the callback. Option C passes a variable named data, which is also valid, assuming data is a reference to a function defined elsewhere in the scope.
A. Async runParallel () .then(data);
The async keyword is used to define a function, not to invoke it. This statement is a syntax error.
B. runParallel ( ). done(function(data){return data;});
The .done() method is not part of the standard ECMAScript Promise API, which is used by Salesforce Lightning Web Components and modern JavaScript.
1. MDN Web Docs (Mozilla): The async function declaration creates an AsyncFunction object. Each time when an async function is called, it returns a new Promise which will be resolved with the value returned by the async function.
Source: MDN Web Docs, "async function". (See the "Return value" section).
2. MDN Web Docs (Mozilla): The then() method of a Promise object takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise.
Syntax: p.then((value) => { / fulfillment handler / })
Source: MDN Web Docs, "Promise.prototype.then()". (See the "Syntax" and "Parameters" sections).
3. Salesforce Lightning Web Components Developer Guide: The guide demonstrates handling asynchronous Apex calls, which return promises, using the standard .then() and .catch() syntax.
Example: getContactList() .then(result => { ... }) .catch(error => { ... });
Source: Salesforce Lightning Web Components Developer Guide, "Call Apex Methods Imperatively".
4. ECMAScript® 2022 Language Specification (ECMA-262): The specification for JavaScript defines the methods available on the Promise prototype. The methods include then, catch, and finally, but do not include done.
Source: ECMA-262, 13th Edition, June 2022, Section 27.2.5 "Properties of the Promise Prototype Object".
Keep practicing
Take the free JAVASCRIPT-DEVELOPER-I practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other JAVASCRIPT-DEVELOPER-I practice questions
- Question 1A developer wants to set up a secure web server withNode.js. The developer creates a dire…
- Question 3Given two expressions var1 and var2. What are two valid ways to return the logical AND of…
- Question 4A test has a dependency on database.query. During the test the dependency is replaced wit…
- Question 5Refer to code below: function Person() { this.firstName = ’John’; } Person.prototype ={ J…
- Question 6A developer has an ErrorHandler module that contains multiple functions. What kind of exp…
- Question 8Refer to the code below: const event = new CustomEvent( //Missing Code ); obj.dispatchEve…
