console.log("start");
Promise.resolve().then(() => {
console.log("promise");
});
console.log("end");
0
What will be the output of the following JavaScript code and why?
kallyani
medium
0completed
5
Answer
The output will be:
start
end
promise- JavaScript executes synchronous code first.
console.log("start")runs immediately.Promise.resolve().then(...)schedules its callback in the microtask queue.console.log("end")runs immediately after, because it is synchronous.- After the call stack is empty, JavaScript executes microtasks.
- The Promise callback runs and logs
"promise".
Click to Reveal Answer
Tap anywhere to see the solution
Revealed
Comments0