ES6 Flashcards
What is a code block? What are some examples of a code block?
A block of code, examples being Functions, Objects and Array
What does block scope mean?
Means the code inside is not accessible from outside the block. (What happens in the code block stays in the code block)
What is the scope of a variable declared with const or let?
Block Scope
What is the difference between let and const?
let values can be reassigned,
while a const values are read only
Why is it possible to .push() a new value into a const variable that points into an Array?
You are able to manipulate an array declared with const but you are unable to reassign it
How should you decide on which type of declaration to use?
Depending if you want to read only or reassign the variable, if you don’t know ALWAYS use const first
What is the syntax for writing a template literal?
Backsticks (
)
Newline (\n)
Newline continuation (\n)
Substitution ( ${expression} )
What is “string interpolation”
A combination of a string and outputs inside the string
What is restructuring, conceptually?
The breakdown of an array or object
What is the syntax for Object destructuring?
const or let [ var, var, var… ] = Object
What is the syntax for Array destructuring?
const or let {var, var, var… } = Array
How can you tell the difference between destructuring and creating Object/Array literals?
When creating an Object/Array the equal sign goes before the curly brace
When destructuring the equal sign goes after the curly brace
What is the syntax of an arrow function?
() => expression
param => expression
(param) => expression
(param1, paramN) => expression
() => {
statements
}
param => {
statements
}
(param1, paramN) => {
statements
}
When an arrow function’s body is left without curly braces, what changes its functionallity?
becomes an expression rather than a statement
How is the value of this determined within an arrow function?
Within an arrow function the this is not binded to the function
What are the three states of 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?
With .then()
How do you handle the rejection of a Promise?
With .catch()
What does Array.filter do?
Creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
What should the callback function return?
If value is true an array of matching values is returned
What is Array.filter useful for?
To filter out unwanted/ wanted values
What does Array.map do?
Creates a new array populated with the results of calling a provided function on every element in the calling array.
What should the callback function return?
Returns a copy of an array with the given expression
What is Array.map useful for?
To modify everything in an array without looping through it