"await" seems successfully extract all nested Promises, why?

Viewed 38

I was interested in "await" behavior, so I ran this code

console.log(await Promise.resolve(Promise.resolve(Promise.resolve("hahaha"))));

in my browser console, the result is correct "hahaha". It seems there is a hidden loop in "await" till no Promise remains. I didn't find explanation from MDN. Anybody knows why? Thanks.

1 Answers

From the MDN documentation:

This function flattens nested layers of promise-like objects (e.g. a promise that fulfills to a promise that fulfills to something) into a single layer — a promise that fulfills to a non-thenable value.

"hahaha" is the non-thenable value that it fullfills to.

Related