Class 35 Flashcards

1
Q

What would happen in this code?
function houseOne(){
console.log(‘Paper delivered to house 1’)
}
function houseTwo(){
console.log(‘Paper delivered to house 2’)
}
function houseThree(){
console.log(‘Paper delivered to house 3’)
}
houseOne()
houseTwo()
houseThree()

A

Paper delivered to house 1
Paper delivered to house 2
Paper delivered to house 3

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

What would happen in this code?
function houseOne(){
console.log(‘Paper delivered to house 1’)
}
function houseTwo(){
setTimeout(() => console.log(‘Paper delivered to house 2’), 3000)
}
function houseThree(){
console.log(‘Paper delivered to house 3’)
}
houseOne()
houseTwo()
houseThree()

A

Paper delivered to house 1
Paper delivered to house 3
Paper delivered to house 2

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

What is a callback?

A

A function that has been passed as an argument

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

What is a higher order function?

A

A function that takes another function as an argument

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

What would happen in this code?
function houseOne(){
console.log(‘Paper delivered to house 1’)
}
function houseTwo(callback){
setTimeout(() => {
console.log(‘Paper delivered to house 2’)
callback()
}, 3000)
}
function houseThree(){
console.log(‘Paper delivered to house 3’)
}
houseOne()
houseTwo(houseThree)

A

Paper delivered to house 1
(After 3 seconds)
Paper delivered to house 2
Paper delivered to house 3

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

When does callback fire?

A

When async task or another function is done
(We waited for the set timeout to finish, then the callback fires right after)

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

What would happen in this code?
function houseOne(){
setTimeout(() => {
console.log(‘Paper delivered to house 1’)
setTimeout(() => {
console.log(‘Paper delivered to house 2’)
setTimeout(() => {
console.log(‘Paper delivered to house 3’)
}, 3000)
}, 4000)
}, 5000)
}
houseOne()

A

(After 5 seconds)
Paper delivered to house 1
(After 4 seconds)
Paper delivered to house 2
(After 3 seconds)
Paper delivered to house 3

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

What is a promise?

A

A promise is an object that represents the eventual completion or failure of an async operation and its value;
An object that may have a value in the future

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

What are 3 possible states a promise can have?

A
  1. pending: initial state (neither fulfilled nor rejected)
  2. fulfilled: operation was completed successfully
  3. rejected: operation failed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is .then() ?

A

A promise object METHOD that runs after promise “resolves”

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

What is .then(value)?

A

Whatever value the promise objet has gets passed as an argument

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

How does fetch API relate to promise?

A

Fetch API returns promise

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

What is await?

A

Await waits for an async process to complete inside an Async function

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

For backend development, what do servers need?

A

Disk access (hard drive/ssd) and network access (internet request / responses)

Servers serve up files (files are stored in disk, hard drive or ssd)
Servers need to hear a request for those files and respond with those files (Servers need access to the internet)

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

Explain about js and its single-threaded and synchronous nature

A

JS is single threaded and synchronous, meaning it can only do one task at a time. In order for program to continue with flow (without any blocking and stopping), JS will hand off a lot of asynchronous tasks to the browser (JS runs in the browser environment). Eventually, web APIs from the browser will respond back and JS need to handle those responses. JS deals with responses with callbacks, promises, and async/await

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

Is Fetch part of javascript?

A

No, Fetch is a web API, which is part of a web browser

17
Q

What does web API return?

A

Promises

18
Q

What’s the difference between Fetch API, Node.js and Express?

A

Fetch API primarily used on client-side (in web browser) to make requests to server and handle responses asynchronously
Node.js and Express are for server-side development.

19
Q
A