ES6 Flashcards
What is a code block? What are some examples of a code block?
the opening and closing of curly braces { } (denoted by curly braces). for, if, while are examples of code block.
What does block scope mean?
the variable defined within a block (code block) will not be accessible from outside the block (code block)
What is the scope of a variable declared with const or let?
they are blocked-scope. while var function-scope.
What is the difference between let and const?
variable declared with a const
won’t be reassigned read-only reference. variable declared with a let
may be reassigned, mutable (such as a counter in a loop, or a value swap in an algorithm.)
Why is it possible to .push() a new value into a const variable that points to an Array?
method .push() does not reassign the array. in const adding/removing elements is allowed since it’s not a reassignment. push() is mutation same as pop etc.
How should you decide on which type of declaration to use?
use let if the variable is reassigned at any time of the code, else use const if not being reassigned.
What is the syntax for writing a template literal?
by wrapping text in backticks ( string string ${'yoon'.toUpperCase()}
)
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
extracting elements from arrays or properties from objects, and assigning them to different variables.
What is the syntax for Object destructuring?
const { property: theNewVariable, property: theNewVariable, propKey(if want same variable) } = object
What is the syntax for Array destructuring?
const [ variable, variable] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
It is located on the left side of the assignment operator
when creating a object/array literals, a variable name is followed by the var, let, const keyword. however in destructuring, object literal or array literal is followed by those keywords.
What is the syntax for defining an arrow function?
var, let, const(keyword) variable = (param(s)) => { statements }
(param1, param2) => {
return;
};
param => expression;
() => expression;
When an arrow function’s body is left without curly braces, what changes in its functionality?
without the curly braces { } the arrow function has an implicit return. evaluated as an expression and returned.
How is the value of this determined within an arrow function?