CodePlumage pfp
CodePlumage
@web3knight
Can you answer?☺️ ☺️ What is the result of below code? const promise = new Promise((resolve, reject) => { console.log(1); setTimeout(() => { console.log("timerStart"); resolve("success"); console.log("timerEnd"); }, 0); console.log(2); }); promise.then((res) => { console.log(res); }); console.log(4);
8 replies
0 recast
0 reaction

Qu1v3r18 pfp
Qu1v3r18
@qu1v3r18
The code resolves the promise with "success" immediately, even though there's a setTimeout function with a 0ms delay, because the event loop runs before the timer starts.
0 reply
0 recast
0 reaction