'I am trying to assign value to varibale outside of callback function but it is not assigning value ans shows udefined
So basically I am writing one program where I am converting values from one currency to another. My function looks like this, I am using OpenExchangeRates API to get value Package doc is this. and fx is a submodule of OXR which is this
async function convertToAnotherCurrency(base, toConvert, amountToBeConverted) {
var convertedValue;
await oxr.latest(async () => {
fx.rates = oxr.rates;
fx.base = oxr.base;
convertedValue = await fx(amountToBeConverted).from(base).to(toConvert);
console.log(convertedValue); //this is logging expected response
});
console.log(await convertedValue); // this is showing undefined
}
Can anyone help me figure out what I am doing wrong or help me with suggestions?
Thank you in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
