angular-interview-questions icon indicating copy to clipboard operation
angular-interview-questions copied to clipboard

What is the expected order of execution for the following JavaScript code snippet, considering asynchronous operations and the event loop?

Open amitkumartech opened this issue 1 year ago • 0 comments
trafficstars

What is the expected order of execution for the following JavaScript code snippet, considering asynchronous operations and the event loop?

console.log("1. Initial console.log");

setTimeout(() => { console.log("2. setTimeout callback"); }, 0);

fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log("3. Fetch response:", data));

Promise.resolve('Promise resolved') .then(value => console.log("4. Promise resolved:", value));

amitkumartech avatar Oct 27 '24 11:10 amitkumartech