I am a beginner in JS and I have difficulty understanding why the output of my var is "Undefined." My JS runs a GET to download a JSON file and with a function, I am trying to read the file and return the first line:
invest.stock('APPLE', function (err, data) {
if (err) { console.log('ERROR', err); return; }
var APPLE_price = data.order[0]['price'];
console.log(APPLE_price); //until here works fine
});
console.log(APPLE_price); //output "Undefined" var
I tried declare the var previously, I created a statement to wait the var (because was a async function) but nothing works.