JAVASCRIPT-DEVELOPER-I practice question 8 of 30
Refer to the code below: const event = new CustomEvent( //Missing Code ); obj.dispatchEvent(event); A developer needs to dispatch a custom event called update to send information about recordId. Which two options could a developer insert at the placeholder in line 02 to achieve this? Choose 2 answers
Full set: 219 questionsDomain Browser and Events
To dispatch a custom event with data in Lightning Web Components, the CustomEvent constructor is used with the signature new CustomEvent(eventName, options). The eventName is a string, and options is an object where the data payload is passed within a property named detail.
Option D, ‘Update’ , {Details : {recordId : ‘123abc’}}, correctly provides a string as the first argument and an object as the second. However, it uses the property name Details (uppercase 'D'). The correct property name is detail (lowercase 'd'). Assuming Details is a typo for detail, this option correctly encapsulates the recordId within the event's data payload.
A. ‘Update’ , (recordId : ‘123abc’( This option is syntactically invalid JavaScript. The use of parentheses () instead of curly braces {} for an object literal is a syntax error.
B. ‘Update’ , ‘123abc’ This is incorrect because the second argument to the CustomEvent constructor must be an options object, not a string. The data would not be correctly attached.
C. { type : ‘update’, recordId : ‘123abc’ }
This uses a single object argument, which is an incorrect signature for the CustomEvent constructor. The event type must be the first string argument.
1. Salesforce Lightning Web Components Developer Guide:
Section: Communicate with Events > Create and Dispatch Events.
Content: The guide explicitly shows the correct syntax: const myEvent = new CustomEvent('eventname', { detail: { ... } });. This confirms that data must be passed in an object with a detail property. This invalidates options A, B, and C, and shows the case-sensitivity error in option D.
2. MDN Web Docs (Mozilla):
Document: CustomEvent() constructor.
Content: The documentation for the web standard defines the second parameter as an object, CustomEventInit, which can contain a detail property for passing data. It states, "The CustomEvent.detail read-only property returns any data passed when initializing the event." This confirms that properties other than detail (like Details in option D) will not be accessible via the standard mechanism.
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 9Refer to the code below: Let foodMenu1 = [‘pizza’, ‘burger’, ‘French fries’]; Let finalMe…
