I am studying async and await in javascript, and a little bit confused about the execution order of the following function I wrote when I play around async and await:
const promiseA = new Promise((resolutionFunc, rejectionFunc) => {
setTimeout(() => resolutionFunc(666), 5000);
});
const test = async () => {
await promiseA.then((val) =>
console.log("asynchronous logging has val:", val)
);
};
const testTwo = () => {
test();
console.log("immediate logging");
};
testTwo();
my understand is that in function <testTwo()>, <test()> execute first, it’s been called & executed, <test()> is an async function, and I have put the await in front of the promise.
why this console.log("immediate logging");
line of code get executed first?
on the other hand, if I wrote <testTwo()> like following:
const testTwo = async () => {
await test();
console.log("immediate logging");
};
everything is fine