JS Fundamentals 3 - ES6 Async Flashcards

1
Q

Pyramid of Doom

A

Deeply nested async code
Built from dependent async fns that can potentially all have errors.
Avoid with: Promise, .then, and try/catch

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

Promise syntax

A

roughly:
new Promise( (resolve, reject) =>
try {
resolve(‘abc’)
catch (e){
reject(e)

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

Async/Await

A

async keyword allows the fn to have await expressions, which make promise-returning fns behave like synchronous code

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

Promise methods - value passed in

A

Promise.resolve(value) - creates a promise that resolves w/the value passed in.
Promise.reject(value) - creates a promise that rejects w/the reason passed in.
Used when you want to start a Promise chain OR when you want to turn a value or error into a Promise. Also useful for testing.

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

Promise methods - Concurrency

A

Not true concurrency, but control switches making it appear they are running at once
All of these take an iterable of promises as input:
.all - fulfills when ALL fulfill, rejects when ANY reject
.allSettled - fulfills when ALL are settled
.any - fulfills when ANY fulfill, rejects when ALL reject
.race - fulfills when ANY fulfill, rejects when ANY reject

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

Breakpoints

A

Sources tab, click on line num.
Code pauses, allows you to examine the variables, execute commands in the console, etc.
Watch has current values for any expressions you add, Call Stack has nested calls chain, Scope has current variables.
Add debugger; to code, and it functions the same way.

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

Breakpoint step actions

A

“Step” = runs the next command, ignores async
“Step over” = run next command but don’t go into a fn - good when you aren’t interested to see what happens in that fn call
“Step into” = similar to step but will run async
“Step out” = continue till the end of the current fn - stops at last line of current fn

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