0
Highcharts.getJSON('https://demo-live-data.highcharts.com/aapl-c.json', function (data) {
        console.log(typeof(Highcharts.stockChart));
    
});

I want to pass data outside the function,what should I do?

d=Highcharts.getJSON('https://demo-live-data.highcharts.com/aapl-c.json', function (data) {
        console.log(typeof(Highcharts.stockChart));
                return data
    
});
function info2(name,age){
    ls=[name,age];
    this.name=name;
    return ls;
    
}
d=info2('mary',20)

I tried to return the value like normal function,but it doesnt work in the first code.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • *I tried to return the value like normal function* - it's not a "normal function", it's an ajax call with a callback – freedomn-m Apr 10 '23 at 17:05
  • Sorry,I am noob in javascript.I used to write python a lot.I think the return value of a function is passed through return.I dont understand how to get the return value of this ajax call (what exactly it is,is it a function or somthing else?) – greatcutter Apr 11 '23 at 02:52
  • I also tried to define a global variable like 'var d' and change it inside this function but it doesnt work. – greatcutter Apr 11 '23 at 03:01
  • *return value of a function is passed through return* - yes, but you have to look at *where* that `function` is defined. `function simple(arg) { return arg; }` vs `function callback(arg) { setTimeout(function() { return arg }, 1); }` - in the 2nd, the `return` is for the *inner* function, there's no `return` for `callback()`. This is similar to how ajax calls work. – freedomn-m Apr 11 '23 at 05:23

0 Answers0