Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

In JavaScript, what is the primary responsibility of the event loop?

View

When does the event loop add a callback to the call stack?

View

What is the purpose of the microtask queue in the event loop?

View

What is the difference between the microtask queue and the task queue?

View

What happens when a promise resolves in JavaScript?

View

Which of the following will be executed first in the event loop?

View

How are setTimeout() callbacks scheduled in the event loop?

View

How does the event loop handle setTimeout() with a 0-millisecond delay?

View

How can you ensure that a promise is handled before any setTimeout() callback?

View

What is the purpose of process.nextTick() in Node.js?

View

In JavaScript, what is the primary responsibility of the event loop?

To manage the execution of asynchronous code.
To execute synchronous code.
To handle variable declarations.
To manage memory allocation.

When does the event loop add a callback to the call stack?

When the call stack is empty and the callback is ready to be processed.
When the call stack is full.
Immediately after an asynchronous function is called.
At the beginning of the program execution.

What is the purpose of the microtask queue in the event loop?

To store high-priority tasks like resolved promises that need to be handled immediately after the current task finishes.
To delay tasks until the task queue is processed.
To manage synchronous code execution.
To hold user input events.

What is the difference between the microtask queue and the task queue?

The microtask queue has higher priority and is processed before the task queue.
The task queue has higher priority and is processed first.
The task queue is for synchronous code, while the microtask queue is for asynchronous code.
There is no difference; both handle tasks at the same time.

What happens when a promise resolves in JavaScript?

It is placed in the microtask queue to be handled after the current code finishes execution.
It is immediately pushed to the call stack.
It is added to the task queue.
It blocks the event loop until the promise resolves.

Which of the following will be executed first in the event loop?

A resolved promise.
A setTimeout() callback with a delay of 0 milliseconds.
An asynchronous I/O operation.
A synchronous console.log() statement.

How are setTimeout() callbacks scheduled in the event loop?

They are added to the task queue after the specified delay.
They are executed immediately after the delay.
They are added to the call stack.
They are added to the microtask queue.

How does the event loop handle setTimeout() with a 0-millisecond delay?

The callback is added to the task queue, but other tasks may still be processed before it.
It skips the task queue and runs immediately.
It is added to the microtask queue.
The function is executed synchronously.

How can you ensure that a promise is handled before any setTimeout() callback?

Use a Promise.race() with setTimeout().
Promises are automatically handled first because they are placed in the microtask queue.
Add the promise to the task queue.
Use process.nextTick().

What is the purpose of process.nextTick() in Node.js?

It delays execution by one loop iteration.
It adds tasks to the task queue.
It adds a callback to the next event loop iteration before any I/O tasks or timers are processed.
It clears the call stack.