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

150
Views
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 answers
Answer question

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 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!