The script below returns promise, there is an array inside it with two index, i want to get index=0 and index=1 separately and output them, how can i do it without using console.log?
async function a1(callback) {
var a = 2 + 2;
return await [a, callback()];
}
async function a2() {
var b = 2 + 3;
return await b;
}
console.log(a1(a2));
My question for Artash Grigoryan
>Solution :
In javascript, async functions always return promise.
I am not entirely sure about your intentions here, but looking at your drawing I would assume that you need to add an extra await on lines 3 and 9.
This code should work for you:
async function a1(callback) {
var a = 2 + 2;
return await [a, await callback()];
}
async function a2() {
var b = 2 + 3;
return await b;
}
await a1(a2);
Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

