Advanced JS Flashcards

1
Q

What is Array.prototype.filter useful for?

A

Creating a new array while excluding some elements

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

What is Array.prototype.map useful for?

A

Creating a new array containing the transformed elements of another

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

What is Array.prototype.reduce useful for?

A

Combining the elements of an array into a single value.

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

What are the three states a Promise can be in?

A

pending (initial state), fulfilled, rejected

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

How do you handle the fulfillment of a Promise?

A

promise.then(),

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

How do you handle the rejection of a Promise?

A

promise.catch()

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

What is a promise?

A

The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

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

What does fetch() return?

A

a promise containing response object

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

What is the default request method used by fetch()?

A

get

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

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

inside the optional init object as a second argument to fetch()

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

spread operator (…)

A
  • used to split up array elements OR object properties
  • ‘pulls out’ the elements (otherwise the entire array or object is placed)
  • makes a COPY of the properties in an object, not a reference
  • ex 1: (will add items in old array to new array)
    const newArr = […oldArr, 1, 2]
  • ex 2: (pulls out properties and values from old object and adds to new object, BUT if they have same property, new property would override old property)
    const newObj = {…oldObj, newProp: 5}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

rest operator (…)

A
  • used to merge a list of function arguments into an array
  • ex: (turns args => [ ])
    function sortArgs(…args) {
    return args.sort();
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly