Asynchronous Programming Flashcards

1
Q

What is another word for sequential code?

A

synchronous code

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

describe sequential/synchronous code

A

The browser evaluates each line in this program, one at a time. For each line of code, the next line of code must wait until the current line completes.

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

Is this code sequential/synchronous?
function logger(object) { // 1
console.log(object); // 4 5 6 7
}

let numbers = [3, 7, 25, 39]; // 2
numbers.forEach(logger); // 3
console.log(numbers.length); // 8

A

Yes, still sequential

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

What happens?

// Be sure you run this code from a file!

setTimeout(function() {
console.log(‘!’);
}, 0);

setTimeout(function() {
console.log(‘World’);
}, 0);

console.log(‘Hello’);

A

Hello
!
World

For now, just realize that code being run by setTimeout only runs when JavaScript isn’t doing anything else. That means that your program must stop running before code executed with setTimeout will even begin to run. Even if your program runs for days at a time, any code executed by setTimeout will not run until your program has no more code to run. No matter how small the delay period, nothing will happen.

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

How to use setTimeout()

A

the arguments are:
handler/function/arguments

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

repeat a bit of code on a timer

A

setInterval(function, time)

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

cancel an interval after 4 seconds

A

let purple = setInterval((abc) => {console.log(abc)}, 200, ‘abadfa’);

setTimeout(clearInterval, 4000, purple);

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

Universal rule to name functions (2 things)

A

One of the more universal, yet simple rules is: Function names should be verbs if the function changes the state of the program, and nouns if they’re used to return a certain value.

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

How do you have multi line string (not using backticks)

A

escape the new ‘enter’
‘blah blah \
blah blah’

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

How to avoid input a whole bunch of parameters

A

input an object with properties

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