When I run the script (see below), the first attempt fails to get the result,
the "result" variable outputs "underfined"
var result;
Promise.resolve('information')
.then(res => {return result=res})
result;
Attempt #1
On the second attempt , the values are already assigned
Question: How can I expect to assign a value to the "result" variable, without using setTimout
and console.log
Waiting with a While loop
var result;
var finito = false;
Promise.resolve('information')
.then(res => {return result=res})
while(finito != true)
{
if (result != undefined)
{
result;
finito=true;
}
}
My question for Jay Surya:
This code does not work
My question for Azarro: