document.querySelector('input').addEventListener('change', e => {
const { files: [ file ] } = e.target;
if (file) {
const reader = new FileReader();
reader.onload = e => document.querySelector('img').src = e.target.result;
reader.readAsDataURL(file);
}
});