Exam JavaScript-Developer-I Topic 2 Question 108 Discussion

Actual exam question for Salesforce's JavaScript-Developer-I exam
Question #: 108
Topic #: 2
Refer to the following code:
< html lang= " en " >
< body >
< button class= " secondary " > Save draft < /button >
< button class= " primary " > Save and close < /button >
< /body >
< script >
function displaySaveMessage(event) {
console.log( ' Save message. ' );
}
function displaySuccessMessage(event) {
console.log( ' Success message. ' );
}
window.onload = function() {
document.querySelector( ' .secondary ' )
.addEventListener( ' click ' , displaySaveMessage, true);
document.querySelector( ' .primary ' )
.addEventListener( ' click ' , displaySuccessMessage, true);
}
< /script >
< /html >

Suggested Answer: B Vote an answer

The answer choices appear to belong to an event propagation question using nested elements such as an outer element and an inner element.
The important clue is this third argument:
addEventListener( ' click ' , handlerFunction, true);
When the third argument is true, the event listener runs during the capturing phase .
In event capturing, the browser handles the event from the outside toward the inside:
Outer element # Inner element
So, if an inner element is clicked and both the outer and inner elements have click listeners registered with capture mode set to true, the outer listener runs first, then the inner listener runs.
That produces:
Outer message
Inner message
So the matching option is B .
Important correction:
In the exact code shown, the buttons are sibling elements:
< button class= " secondary " > Save draft < /button >
< button class= " primary " > Save and close < /button >
They are not nested inside one another. Therefore, with the code exactly as written:
Clicking the secondary button logs:
Save message.
Clicking the primary button logs:
Success message.
However, because the provided answer choices refer to Outer message and Inner message , the intended concept is clearly event capturing. In a capturing-phase question with nested outer and inner elements, the correct order is:
Outer message
Inner message
Therefore, the verified answer for the intended event-capturing question is B .

by Adam at Aug 20, 2026, 10:07 PM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10