Good afternoon in my timezone.
I have been reading about Promises and Async functions, and i come across a page where there is an example with code :
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x * 2);
}, 2000);
});
}
async function addAsync(x) {
const a = await doubleAfter2Seconds(10);
const b = await doubleAfter2Seconds(20);
const c = await doubleAfter2Seconds(30);
return x + a + b + c;
}
var toLog = addAsync(10);
console.log(toLog);
I used the JSFiddle and the Chrome console : The "toLog" variable is a promise object with the promiseValue of 130.
Questions :
Inside the doubleAfter2Seconds function the sum is made inside the "resolve" function, if in the example we never pass the "resolve" function(through the then method in the promise object i think) how can we get the 130 result ?
Best regards Thanks in advance
130 = 10 + (10 * 2) + (20 * 2) + (30 * 2)- do you know where 130 comes from now? hint:x + a + b + c