JS Runtime Flashcards
(19 cards)
What is the event Loop in JavaScript?
A tiny component within the JavaScript runtime that manages asynchronous tasks.
What does the Call Stack do in JavaScript?
Manages the execution of the program by handling function calls and execution contexts.
True or False: JavaScript is multi-threaded.
False
What happens when a long-running task is executed in JavaScript?
The entire program is frozen until the task is completed.
What are Web APIs in JavaScript?
Interfaces that allow interaction with the browser’s features like DOM, fetch, and timers.
Fill in the blank: The browser handles long-running tasks through _______.
Web APIs
What are Callback-based APIs?
APIs that use callbacks to handle asynchronous operations.
What is the Task Queue?
Also called the Callback queue, it holds web API callbacks and event handlers to be executed later.
What is the role of the Event Loop?
Checks if the call stack is empty and moves tasks from the task queue to the call stack for execution.
What does setTimeout do?
Registers a callback to be executed after a specified delay.
Fill in the blank: The delay specified in setTimeout is the delay until it gets moved to the _______.
Task Queue
What is the Microtask Queue?
A special queue for promise callbacks, async function bodies after await, and mutation observer callbacks.
True or False: The Microtask Queue has lower priority than the Task Queue.
False
What happens when a promise resolves?
A promise reaction is created and pushed to the Microtask Queue.
What is a potential issue with Microtasks?
A microtask can schedule another microtask, potentially creating an infinite loop.
What is Promisifying Callbacks?
Wrapping callback-based APIs in a Promise constructor for better readability.
Recap: What is the main purpose of Web APIs in JavaScript?
To initiate asynchronous tasks in the background without blocking the call stack.
What does the Event Loop ensure after handling each task from the Task Queue?
It checks the Microtask Queue to ensure it’s empty before moving on.
What can help improve understanding of asynchronous JavaScript execution?
Playing around with setTimeout and Microtasks.