ExamGecko
Question list
Search
Search

Question 117 - Certified B2B Commerce Developer discussion

Report
Export

In which two ways can events fired from Lightning web components be handled?

A.
Programmatically adding event listeners
Answers
A.
Programmatically adding event listeners
B.
Adding callbacks to components
Answers
B.
Adding callbacks to components
C.
Listening for all possible events at the document root
Answers
C.
Listening for all possible events at the document root
D.
Attaching handlers to DOM elements
Answers
D.
Attaching handlers to DOM elements
Suggested answer: A, D

Explanation:

Two ways that events fired from Lightning web components can be handled are programmatically adding event listeners and attaching handlers to DOM elements. Programmatically adding event listeners is a way of handling events by using JavaScript code to register functions that are invoked when an event occurs. The developer can use methods such as addEventListener or @wire to add event listeners to components or services that fire events. Attaching handlers to DOM elements is a way of handling events by using HTML attributes to bind functions that are invoked when an event occurs. The developer can use attributes such as onclick or onchange to attach handlers to DOM elements that fire events. Adding callbacks to components is not a valid way of handling events fired from Lightning web components, as it is not related to event handling, but rather to asynchronous programming. Listening for all possible events at the document root is not a valid way either, as it is not efficient or recommended for event handling, as it can cause performance issues or conflicts with other event listeners. Salesforce

Reference: [Lightning Web Components Developer Guide: Handle Events], [Lightning Web Components Developer Guide: Communicate with Events]

asked 23/09/2024
Abid Ali Minhas
35 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first