Advanced JS Flashcards
What is Array.prototype.filter useful for?
Creating a new array while excluding some elements
What is Array.prototype.map useful for?
Creating a new array containing the transformed elements of another
What is Array.prototype.reduce useful for?
Combining the elements of an array into a single value.
What are the three states a Promise can be in?
pending (initial state), fulfilled, rejected
How do you handle the fulfillment of a Promise?
promise.then(),
How do you handle the rejection of a Promise?
promise.catch()
What is a promise?
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
What does fetch() return?
a promise containing response object
What is the default request method used by fetch()?
get
How do you specify the request method (GET, POST, etc.) when calling fetch?
inside the optional init object as a second argument to fetch()
spread operator (…)
- 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}
rest operator (…)
- used to merge a list of function arguments into an array
- ex: (turns args => [ ])
function sortArgs(…args) {
return args.sort();
}