How to fetch data then save inside a variable?
var store;
fetch('https://api.coindesk.com/v1/bpi/historical/close.json?start=2013-09-01&end=2013-09-05')
.then(function(response) {
return response.json();
})
.then(function(data) {
store = data;
console.log('Data is', store);
})
.catch(function(err) {
console.log('Unable to fetch the data', err);
});
console.log(store);
console.log gives me undefined variable. Can someone describe how does it work?