0
var options;
fetch("https://api.covid19api.com/countries").then(function(response) {
  return response.json();
}).then(function(obj) {
  options = "jas";
}).catch(function(error) {
  alert(error);
});

console.log(options);

The value of "options" variable should be "jas" but in console undefined is showing.Can any one describe what i and doing wrong.

i want to print "jas",what should i do to achieve it? please help me

naveen
  • 53,448
  • 46
  • 161
  • 251
  • 4
    You're looking at it **before** the callback function has executed. – Quentin May 20 '20 at 13:18
  • 1
    `fetch()` is an `async` function that returns a `Promise`. `.then` is executed when the `Promise` is resolved. You are trying to log the new value before the `Promise` is resolved and the new value is set – naveen May 20 '20 at 13:23

0 Answers0