Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
La declaración de devolución no funciona según lo previsto

Así que estaba trabajando con esta línea de código para convertir una imagen de entrada en una URL, sin embargo, el retorno no parece estar funcionando ya que no puedo acceder a la constante en ningún otro lugar del documento donde realmente la necesito.

 window.addEventListener('load', function() { document.querySelector('input[type="file"]').addEventListener('change', function() { if (this.files && this.files[0]) { const imageURL = URL.createObjectURL(this.files[0]); return imageURL; } }); });

Todavía soy nuevo en JavaScript, así que por mi vida no puedo encontrar por qué no funciona, ¡gracias de antemano!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto se debe a que la URL de imagen constante se incluye en el bloque if, si desea que se acceda a ella en todo el archivo, declárela fuera de la función addEventListener(). Por ejemplo

 let imageURL; window.addEventListener('load', function() { document.querySelector('input[type="file"]').addEventListener('change', function() { if (this.files && this.files[0]) { imageURL = URL.createObjectURL(this.files[0]); } }); }); console.log(imageURL)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!