JavaScript Event Loop Flashcards

1
Q

What is the JavaScript Event Loop?

A

The process of checking if the call stack is empty, and if so, taking off the first element (the first callback) in the queue (if it is not empty, of course 🙄) and pushing it to the stack for it to be executed.

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

What is the Call Stack?

A

That is where our tasks (functions encountered in the code) are stacked. When we encounter a function, we push it to the stack and when we return from that function (returns an output), we pop it off the stack (LIFO).

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

JavaScript is single-threaded? What does that mean?

A

In simple words, JavaScript can only do one thing at a time (one call stack). One element (function) in the stack is executed at a time.

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

JavaScript is non-blocking?

A

It means that whenever a “slow” task is encountered in the call stack, it doesn’t block the execution of the following tasks.

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

JavaScript is asynchronous. What does that mean?

A

The non-blocking behavior we explained before is done by using asynchronous callbacks which means that we run the “slow” task, give it a callback (an action to do when it’s done), and run that callback later.

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

What is a Callback Queue and how does it work?

A

It is basically the place where the callbacks are queued (FIFO) waiting for their turn to be called by our MVP, the call stack 😎

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

Looking at the provided image, in what order will the returns of foo, bar, and baz print to the console?

A
  • First
  • Third
  • Second
How well did you know this?
1
Not at all
2
3
4
5
Perfectly