Asynchronous / Synchronous JS Flashcards

1
Q

Is JavaScript single-threaded?

A

Yes.

It is also synchronous (processes one operation at a time).

Blocking.

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

Why is JS running in the browser important?

A

Browsers have a BUNCH of APIs we can use that are async and enable us to keep looking at a cute cat photo while those operations are being processed asynchronously.

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

Is the DOM an API?

A

The DOM is essentially the API one uses to manipulate an HTML (or XML) document – usually using JavaScript.

The DOM is not something that comes with JavaScript.

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

What did jQuery provide?

A

Cross browser compatibility.

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

Are setTimeout and setInterval part of the JavaScript specification?

A

No, but most environments include them.. like all browsers and Node.js

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

How are callbacks used?

A

Wait for something to happen, and then do something else.

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

What is a Higher Order Function?

A

A function that takes another function as an argument.

Ex. addEventListener( ‘click’, callback).

addEventListener() is the higher order function.

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

What is a callback?

A

The function that is passed in as an argument in a higher order function.

(Callbacks are not really “a thing” in JS, just a convention).

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

What is a Promise?

A

An object that represents the eventual completion or failure of an async operation and its value.

AKA, an object that may have a value in the future.

Like a placeholder.

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

Possible states of a promise.

A

3 States.

-Pending: initial state, neither fulfilled nor rejected.

-Fulfilled: meaning that the operation was completed successfully.

-Rejected: meaning that the operation failed.

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

.then()

A

A promise object method that runs after the promise “resolves”.

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

.then(value)

A

Whatever value the promise object has gets passed as an argument.

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

What does the fetch() browser API return?

A

A promise.

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

T or F: JS is a language that can only do what the hosting environment allows?

A

True.

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