Question 16
Back to Exercise
The page contains this HTML:
<a id="link" href="/exam">Start exam</a>What does the following JavaScript code print when it runs on this page?
const link = document.getElementById("link");
link.addEventListener("click", (e) => e.preventDefault());
const a = link.dispatchEvent(new Event("click", { cancelable: true }));
const b = link.dispatchEvent(new Event("click"));
console.log(a, b);
- A true true
- B false false
- C true false
- D false true Correct
Correct Answer: Option D
dispatchEvent returns false only if the event was cancelable and a listener called preventDefault; on a non-cancelable event preventDefault does nothing.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!