nerdexam
CIW

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…

Client-Side Scripting and Media Queries

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)
  • A
    4% (1)
  • B
    92% (24)
  • C
    4% (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; Img is not a valid constructor. The correct built-in is Image, not Img.
  • C. HREF - HREF is an HTML attribute on anchor tags (<a>), not a JavaScript object used for image loading.
  • D. RollOver - There is no native JavaScript RollOver object; 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

#Image object#Image preloading#Browser caching#Client-side scripting

Community Discussion

No community discussion yet for this question.

Full 1D0-720 Practice