function f() {
console.log("A");
setTimeout(() => console.log("F"))
new Promise((resolve, reject) => {
console.log("B");
resolve();
console.log("C");
}).then(() => console.log("E"));
console.log("D");
}
f();
output result is
A
B
C
D
E
F
setTimeout
is easier to understand, which is actually Event Loop
, but Promise
is not well understood. Can anyone explain how Promise works inside? Why E and then F?