ES6 Flashcards
What is a code block? What are some examples of a code block?
Blocks are notated by curly braces, loops often times
What does block scope mean?
Means that the variable within the block will not be accessible from outside the block.
What is the scope of a variable declared with const or let?
Block scope
What is the difference between let and const?
let ‘s value can be reassigned const can not.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because we can change the arrays elements but we cannot reassign the const variable to a new array.
How should you decide on which type of declaration to use?
if the value needs to be reassigned, use let, otherwise use const.
What is the syntax for writing a template literal?
` text ${expression}`
What is “string interpolation”?
the JavaScript engine will automatically replace these variables ${} and expressions with their values
What is destructuring, conceptually?
were taking properties or array element values, extracting them to their own variables.
What is the syntax for Object destructuring?
let {propKey1: propAlias1, lastname} = object.
What is the syntax for Array destructuring?
let [x,y,z] = array
How can you tell the difference between destructuring and creating Object/Array literals?
the curly brackets are on the left side of the assignment operator.
What is the syntax for defining an arrow function?
(param1, param2) => {
return;
}
param => exp;
() => exp;
When an arrow function’s body is left without curly braces, what changes in its functionality?
evaluated as an expression not a statement. result of that expression is returned, implicit return.
How is the value of this determined within an arrow function?
lexically, it takes the this from the enclosing function. it is determined at definition for arrow functions. call time for es5 functions.