XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
Event Loop and Asynchronous JavaScript
Understand how promises,async/await,and the event loop work.
1. What is the primary role of the Event Loop in JavaScript?
Manages memory allocation for variables
Coordinates execution of code between the call stack and callback queues
Executes code synchronously from top to bottom
Compiles JavaScript code to machine language
2. Which of the following is classified as a microtask?
setTimeout
Promise.then()
setInterval
requestAnimationFrame
3. The Event Loop is responsible for moving callbacks from the task queue to the call stack when the call stack is empty.
True
False
4. What term refers to a function passed as an argument to another function to be executed later?
5. Select all examples of macrotasks.
setTimeout
Promise.resolve().then()
setImmediate (Node.js)
requestAnimationFrame
queueMicrotask()
6. After the call stack is empty, which type of task is executed first by the Event Loop?
Macrotasks
Microtasks
Both simultaneously
Neither; the loop exits
7. Async/await syntax is syntactic sugar built on top of Promises.
True
False
8. What keyword is used to pause execution of an async function until a Promise is resolved, returning its result?
9. Which statements about the JavaScript call stack are true?
It follows LIFO (Last In, First Out) order
It stores variables declared in functions
It executes functions sequentially as they are called
It can cause a stack overflow if too many functions are called recursively
10. What occurs when a Promise is rejected but no .catch() handler is provided?
The error is silently ignored
An 'unhandled promise rejection' warning is thrown
The Event Loop is blocked indefinitely
The Promise automatically resolves with undefined
11. Microtasks are executed after all macrotasks in each iteration of the Event Loop.
True
False
12. Name the JavaScript engine used in Google Chrome and Node.js (full name).
13. Which of the following are sources of microtasks?
Promise.then()
queueMicrotask()
MutationObserver
setTimeout
fetch().then()
14. What is the effect of prefixing a function with the 'async' keyword?
The function executes asynchronously immediately
The function returns a Promise object
The function blocks the Event Loop until completion
The function can only contain synchronous code
15. The Event Loop is defined in the ECMAScript specification (JavaScript language standard).
True
False
16. What is the default delay (in milliseconds) for setTimeout when no delay is specified?
17. Which of the following operations can block the Event Loop?
A synchronous for loop with 1,000,000 iterations
Promise.resolve().then(() => { ... })
Reading a large file synchronously using fs.readFileSync()
setTimeout(() => { ... }, 1000)
An infinite synchronous while loop
18. In the following code, what order will the console logs appear? `console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C'));`
A, B, C
A, C, B
B, A, C
C, A, B
19. Microtasks are processed in the order they are added to the microtask queue (FIFO: First In, First Out).
True
False
20. What term describes a single iteration of the Event Loop, where it processes all microtasks and one macrotask?
Reset
Answered 0 of 0 — 0 correct