JS-Dev-101 practice question 13 of 25
A developer needs the function personalizeWebsiteContent to run when the webpage is fully loaded (HTML and all external resources). Which implementation should be used?
Full set: 148 questionsThe requirement is for the function to run after the HTML and all external resources (like images, stylesheets, and scripts) are fully loaded. The load event on the window object is specifically designed for this purpose. It fires only when the entire page and all its dependent resources have finished loading. In contrast, the DOMContentLoaded event fires earlier, once the HTML document itself has been parsed, without waiting for external resources.
A. The DOMContentLoaded event does not wait for external resources like images, so it does not meet the requirement.
C. The DOMContentLoaded event is incorrect because it fires before all external resources are fully loaded.
D. The load event is correct, but it should be attached to the window object to signify the entire page has loaded, not a specific script element.
1. MDN Web Docs, "Window: load event". "The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images."
2. MDN Web Docs, "Document: 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."
3. W3C, HTML Living Standard, Section 7.6.1 "The load event". "This event fires at the Window object after the document and all subresources have finished loading."
Keep practicing
Take the free JS-Dev-101 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other JS-Dev-101 practice questions
- Question 1A developer executes: document.cookie; document.cookie = 'key=John Smith'; What is the be…
- Question 2A developer is required to write a function that calculates the sum of elements in an arr…
- Question 3Given the code below: 01 const delay = async delay => { 02 return new Promise((resolve, r…
- Question 401 function Animal(size, type) { 02 this.type = type || 'Animal'; 03 this.canTalk = false…
- Question 5Refer to the code snippet: 01 let array = [1, 2, 3, 4, 4, 5, 4, 4]; 02 for (let i = 0; i …
- Question 6Code: 01 let array = [1, 2, 3, 4, 4, 5, 4, 4]; 02 for (let i = 0; i < array.length; i++) …
