ES6 Flashcards
What is destructuring, conceptually?
Assigning properties of an object to individual variables.
What is the syntax for Object destructuring?
let/const followed by opening curly brace, the property name followed by a colon, followed by the variable name. Then closing curly brace for the code block. Then assignment operator with name of object to destructure.
What is the syntax for Array destructuring?
let/const followed by opening square bracket, variable names separated by commas, followed by the closing square bracket. Followed by the assignment operator and the array to destructure.
How can you tell the difference between destructuring and creating Object/Array literals?
In destructuring, the assignment operator appears after the curly braces. (variable name after assignment operator.)
What is the syntax for writing a template literal?
Backticks instead of quotes or double-quotes. Designate a JavaScript expression by using dollar sign then curly braces.
What is “string interpolation”?
Embedding variables and expressions into strings.
What is the syntax for defining an arrow function?
parameter list first, enclosed in parentheses; Followed by arrow ( => ), followed by code statements enlosed in curly braces.
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without braces, you can only use an single-line expression in the body of the arrow function.
How is the value of this determined within an arrow function?
An arrow function captures the ‘this’ value of its enclosing context.
What are the three states a Promise can be in?
pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.
How do you handle the fulfillment of a Promise?
By adding a callback function as the first argument in its ‘then’ method.
How do you handle the rejection of a Promise?
By adding a callback function as the second argument in its ‘then’ method.
What is Array.prototype.filter useful for?
It’s useful for getting just the values you need out of an array and ignoring the rest.
What is Array.prototype.map useful for?
It’s useful for calling a function on every element of an array and assigning the results to a new array, without modifying the original.
What is Array.prototype.reduce useful for?
It’s useful for calling a function on every element of an array and storing the combined result in a single output value. | | For getting a combined value from an array.