CRT-600 practice question 20 of 30
A developer at Universal Containers is creating their new landing page based on HTML, CSS, and JavaScript. The website includes multiple external…
Full set: 223 questionsThe DOMContentLoaded event is the most appropriate choice for this requirement. It fires as soon as the browser has finished parsing the HTML document and the Document Object Model (DOM) is ready. Crucially, it does not wait for external resources like stylesheets, images, or subframes to finish loading. This allows the personalizeWebsiteContent script to execute at the earliest possible moment without being delayed by network requests for other assets, ensuring a responsive experience for the visitor.
A. windows,addEventListener('load', personalizeWebsiteContent);
The load event only fires after the entire page, including all dependent resources (images, CSS), has completely loaded, which contradicts the requirement to not wait for these resources.
C. windows,addEventListener('onload', personalizeWebsiteContent);
The addEventListener method requires the event type name without the "on" prefix. The correct event type is 'load', not 'onload'.
D. windows,addEventListener('onDOMCContentLoaded', personalizeWebsiteContent);
Similar to option C, the correct event type for addEventListener is 'DOMContentLoaded', not 'onDOMContentLoaded'. The "on" prefix is incorrect syntax for this method. ---
1. Mozilla Developer Network (MDN) Web Docs
DOMContentLoaded event: "The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed
without waiting for stylesheets
images
and subframes to finish loading." This directly supports the choice of option B as it meets the requirement to run without waiting for resources.
Source: MDN Web Docs
Document: DOMContentLoaded event. Available at: https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoadedevent
2. Mozilla Developer Network (MDN) Web Docs
load event: "The load event is fired when the whole page has loaded
including all dependent resources such as stylesheets and images. This is in contrast to DOMContentLoaded
which is fired as soon as the page DOM has been loaded
without waiting for resources to finish loading." This explains why option A is incorrect.
Source: MDN Web Docs
Window: load event. Available at: https://developer.mozilla.org/en-US/docs/Web/API/Window/loadevent
3. Mozilla Developer Network (MDN) Web Docs
EventTarget.addEventListener(): The documentation specifies the syntax as addEventListener(type
listener). The type parameter is a case-sensitive string representing the event type to listen for (e.g.
'click'
'load'
'DOMContentLoaded'). This confirms that using an "on" prefix like 'onload' is syntactically incorrect for this method
invalidating options C and D.
Source: MDN Web Docs
EventTarget.addEventListener(). Available at: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
Keep practicing
Take the free CRT-600 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-600 practice questions
- Question 2A developer has the function, shown below, that is called when a page loads. function onl…
- Question 3A developer needs to test this function: 01 const sum3 = (arr) => ( 02 if (!arr.length) r…
- Question 4Refer to the code below: Const resolveAfterMilliseconds = (ms) => Promise.resolve ( setTi…
- Question 10Refer to the following code block: class Animal{ constructor(name){ this.name = name; } m…
- Question 11A developer needs to debug a Node.js web server because a runtime error keeps occurring a…
- Question 12Refer to the string below: const str = 'Salesforce'; Which two statements result in the w…
