ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 63 - Certified JavaScript Developer I discussion

Report
Export

is below:

<input type="file" onchange="previewFile()">

<img src="" height="200" alt="Image Preview…"/>

The JavaScript portion is:

01 function previewFile(){

02 const preview = document.querySelector('img');

03 const file = document.querySelector('input[type=file]').files[0];

04 //line 4 code

05 reader.addEventListener("load", () => {

06 preview.src = reader.result;

07 },false);

08 //line 8 code

09 }

In lines 04 and 08, which code allows the user to select an image from their local computer , and to display the image in the browser?

A.
04 const reader = new File();08 if (file) URL.createObjectURL(file);
Answers
A.
04 const reader = new File();08 if (file) URL.createObjectURL(file);
B.
04 const reader = new FileReader();08 if (file) URL.createObjectURL(file);
Answers
B.
04 const reader = new FileReader();08 if (file) URL.createObjectURL(file);
C.
04 const reader = new File();08 if (file) reader.readAsDataURL(file);
Answers
C.
04 const reader = new File();08 if (file) reader.readAsDataURL(file);
D.
04 const reader = new FileReader();08 if (file) reader.readAsDataURL(file);
Answers
D.
04 const reader = new FileReader();08 if (file) reader.readAsDataURL(file);
Suggested answer: D
asked 23/09/2024
Vahit Erciyas
44 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first