Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
JS - Uncaught TypeError: Cannot read properties of undefined (reading 'value')

I'm trying to receive an API response (which succeeds) but for some reason the variable cannot be called outside the function, but I'm fairly certain it's a global variable and not a local one. What am I doing wrong? I've also tried declaring the variable inside of the function as a parameter.

const data = null;

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

var object1;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === this.DONE) {
        object1 = JSON.parse(this.responseText);
    }
});

document.getElementById('thejoke').innerHTML = object1.value;



xhr.open("GET", "https://api.chucknorris.io/jokes/random?category=explicit");

xhr.send(data);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda