Asynchronus JavaScript Flashcards

1
Q

What is asynchronous execution?

A

asynchronous execution is where we invoke another method/process but continue execution in the code that called it

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

What is the Microtask Queue?

A

an internal queue used by JavaScript engines

determines what task and what actions to execute next

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

Event Loop

A

the event loop is where tasks that are pulled from the microtask queue are executed

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

Callback Functions

A

a callback function is a function that’s passed as an argument to another function to be executed when the first function returns

callback functions are frequently used with asynchronous execution in JavaScript

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

Promises

A

a promise is a proxy for a value that will eventually become available

the promise eventually moves to a resolved or rejected state, invoking either the callback function(s) passed to then or catch, respectively

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

What changes are made to a Promise when it is settled?

A

state initially has a pending value that changes to fulfilled when the resolve callback is invoked or rejected when the reject callback is invoked

result is initially undefined, then changes to the value returned from the promise when the resolve callback is invoked or the error when the reject callback is invoked

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

How do we Consume Promises?

A

we can consume our promises by using “then”, “catch”, and “finally” methods

finally method allows us to execute code regardless fo whether our promise has been resolved/rejected

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

Fetch API

A

the Fetch API is a JavaScript API that we can use in browsers to easily make callouts to external services

when making such a callout, we’ll invoke the fetch() method

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

Async/Await

A
  • async/await is built on promises (it’s just an abstraction that makes for a more readable way to work with promises)
  • functions that begin with the async keyword (which is placed before the function keyword in the function declaration) always return a promise
  • any return statements in an async function that don’t explicitly return a promise will have their values wrapped in a resolved promise
  • the await keyword makes the JavaScript engine suspend function execution until a promise settles and returns a result
  • the await keyword can only be used inside async functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

setTimeout()

A
  • will invoke the callback function passed as the first argument after the amount of time specified has elapsed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

setInterval()

A
  • will invoke the callback function passed as the first argument every interval period
How well did you know this?
1
Not at all
2
3
4
5
Perfectly