Valid JS-Dev-101 Dumps shared by EduDump.com for Helping Passing JS-Dev-101 Exam! EduDump.com now offer the newest JS-Dev-101 exam dumps, the EduDump.com JS-Dev-101 exam questions have been updated and answers have been corrected get the newest EduDump.com JS-Dev-101 dumps with Test Engine here:
A developer wants to create a simple image upload using the File API. HTML: <input type="file" onchange="previewFile()"> <img src="" height="200" alt="Image preview..." /> JavaScript: 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 } Which code in lines 04 and 08 allows the selected local image to be displayed?
Correct Answer: B
________________________________________ Comprehensive and Detailed Explanation From Exact Extract JavaScript Knowledge The File API in browsers provides the FileReader object to read file contents selected from <input type="file">. Important knowledge points: new FileReader() creates a file-reading object. .readAsDataURL(file) reads a file and produces a Base64 URL string. The "load" event fires when the file has finished reading. reader.result contains the data URL after reading completes. Therefore, the correct implementation must: Create a FileReader instance: const reader = new FileReader(); Call: reader.readAsDataURL(file); Use the load event handler to assign the image preview: preview.src = reader.result; Option B is the only option that matches valid JavaScript File API usage. Option A is incorrect because File is not a constructor for reading files. Option C is incorrect because URL.createObjectURL(file) must be assigned directly as a URL, not used with reader.result. ________________________________________ JavaScript Knowledge Reference (text-only) The file-reading interface in browsers is FileReader. readAsDataURL() loads files as Base64 data URLs. The load event indicates when the reader has finished and reader.result is available.