YDKNJS async Flashcards

1
Q

is it possible to handle ajax synchoronasly?

A

yes but it will block the user from interacting with the page

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

what is the simplest way to handle ajax?

A

using a callback

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

is a callback synchronous or asynchronous?

A

asynchronous

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

what is a callback function?

A

it a functions registered in the event loop to run after a task is done like ajax network request

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

is the event loop a stack or a queue?

A

a queue

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

does setTimeout insert function in event loop?

A

no it sets up a timer and after the timer is finished the function gets inserted into the loop

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

what happens if you have multiple callbacks in eventloop?

A

they get executed synchronously one by one

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

what is the difference between parallel and async?

A

async : time between now and later

parallel: things executing simultaneously

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

is js async multi thread or single thread?

A

single thread meaning that data is not shared between threads

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

what is concurrency?

A

it’s when two processes execute simultaneously over the same period of time

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

what is a race condition bug?

A

it’s a bug that occurs when we don’t know whether response 1 or response 2 will come back first with async requests

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

what is a tick in event loop?

A

it’s an iteration of the event loop

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

what is a job queue?

A

it’s a queue that happens after each tick that adds new jobs to the queue immediately after an async item is ran

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

can a job add another job to the event loop?

A

yes

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

can u predict the ordering of async?

A

no you cannot

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

what is the indirection of control?

A

it is when you give control of the execution of your program to a 3rd party API

17
Q

what are some ways of mitigating callbacks inversion of control issue

A

1 - 2 callbacks one for success and one for failure

2 - the first parameter sent in callback is always for error

18
Q

what are the problems of callbacks?

A

1 - lack of sequentially because our brains do not work in async way of callbacks
2 - lack of trust ability because of inversion of control maybe the third party api will not call the callback or even call it multiple times

19
Q

how many functions does a promise .then() have and what do they do?

A

two functions

  • first is for fulfillment
  • second is for rejection
20
Q

is the value inside a resolute promise mutable or immutable?

A

immutable

21
Q

how do we check that something is a promise?

A

we make a thenable which stands for a function or an object that has a .then function