1D0-720 · Question #77
Brent is creating a client-side script to preload images used in rollovers on his Web site. In order for the images to be preloaded into the browser cache, which JavaScript object should Brent…
The correct answer is B. Image. Option B is correct because JavaScript provides a built-in constructor called Image (capital I) that creates an HTMLImageElement object. By doing const img = new Image(); img.src = "photo.jpg";, the browser fetches and caches the image immediately, so rollover swaps feel…
Question
Brent is creating a client-side script to preload images used in rollovers on his Web site. In order for the images to be preloaded into the browser cache, which JavaScript object should Brent instantiate and point to the location of the needed image?
Options
- AImg
- BImage
- CHREF
- DRollOver
How the community answered
(26 responses)- A4% (1)
- B92% (24)
- C4% (1)
Explanation
Option B is correct because JavaScript provides a built-in constructor called Image (capital I) that creates an HTMLImageElement object. By doing const img = new Image(); img.src = "photo.jpg";, the browser fetches and caches the image immediately, so rollover swaps feel instant.
Why the distractors are wrong:
- A.
Img- JavaScript is case-sensitive;Imgis not a valid constructor. The correct built-in isImage, notImg. - C.
HREF-HREFis an HTML attribute on anchor tags (<a>), not a JavaScript object used for image loading. - D.
RollOver- There is no native JavaScriptRollOverobject; this is a made-up distractor.
Memory tip: Think of it as mirroring the HTML tag - <img> in HTML becomes new Image() in JavaScript (just capitalize it and drop the angle brackets). If you remember "HTML img → JS Image()," you'll never confuse the casing again.
Topics
Community Discussion
No community discussion yet for this question.