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

158
Vistas
Can I use variables that are inside functions outside them?
async function players_online() {
    const response = await fetch("http://ip:port/dynamic.json");
    const data = await response.json();
    console.log(data.clients);

    }

Can i use data inside other function? Exemple:

async function players() {
console.log(data.clients);
}

When i do this i recive undefined

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

"Yes", you can:

let data 

async function players_online() {
    const response = await fetch("http://ip:port/dynamic.json");
    data = await response.json();
}

async function players() {
    // You can't ensure data is already set!!!
    console.log(data.clients);
}

However you can not ensure that data is already defined at that point. You have to ensure by your own code that players_online is called and awaited before you call players.

You can ensure this with a call order like that:

async function players_online() {
    const response = await fetch("http://ip:port/dynamic.json");
    const data = await response.json();
    await players(data)
}

async function players(data) {
    console.log(data.clients);
}
about 4 years ago · Juan Pablo Isaza Denunciar
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