165 views
Determining the sequence of message output in the console when combining setTimeout, Promise, and requestAnimationFrame
Task condition
You need to understand the order in which the logs will appear in the console when executing the following JavaScript code, which involves setTimeout, Promise, and requestAnimationFrame.
console.log('Start');
setTimeout(() => {
console.log('Timeout 1');
}, 0);
new Promise((resolve, _) => {
console.log('async request');
resolve();
})
.then(() => {
console.log('Promise 1');
})
.then(() => {
console.log('Promise 2');
});
requestAnimationFrame(() => {
console.log('requestAnimationFrame 1');
});
requestAnimationFrame(() => {
console.log('requestAnimationFrame 2');
});
console.log('End');