Javascript Event Loop Flashcards

1
Q

What are the elements of the javascript event loop?

A

Javascript Engine (Heap & Call Stack)
Web APIs
Task Queue
MicroTask Queue
Event Loop itself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two structures inside the javascript engine?

A

Heap & Call Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are elements of the web api?

A

fetch
setTimeout
localStorage
sessionStorage
HTMLDivElement
indexedDB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which structure holds async callbacks?

A

The task queue, or callback queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the job of the eventloop?

A

The event loops checks the call stack. If the call stack is empty and there is no more code to execute, meaning all synchronous tasks are done, then the event loop pops the next callback off the task queue and onto the call stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the delay signify in setTimeout?

A

The delay signifies when the callback will be added to the task queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which structure do promises use?

A

Promises use the micro task queue. This is because they use the queueMicroTask function under the hood.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is the microTaskQueue prioritized?

A

The microTask queue will be fully emptied and executed when the call stack is empty before anything from the task queue is added to the call stack.

The microTask queue is also checked each time the task queue is popped.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the console output of this code:

Promise.resolve().then(() => console.log(1));

setTimeout(() => console.log(2), 10);

queueMicrotask(() => {
console.log(3);
queueMicrotask(() => console.log(4));
});

console.log(5);

A

5
1
3
4
2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the event loop?

A

The event loop is a piece of code that orchestates and ties together various aspects of the Javascript v8 engine and various browser apis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is more code to be executed represented on the call stack?

A

It is represented as an anonymous function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly