es6 Flashcards
What is a code block? What are some examples of a code block?
a section of code located within a set of curly braces.
Ex. if else, for, do while, while, etc.
What does block scope mean?
If a block-scoped variable is declared within a code block, that variable’s value will only be accessible within that code block.
What is the scope of a variable declared with const or let?
block-scoped
var is function-scoped
What is the difference between let and const?
const is read-only and cannot be reassigned. let values can be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
The array itself is being modified, but the variable name is still pointing to the same array
How should you decide on which type of declaration to use?
Whether a variable’s value will need to be changed or not. If it needs to be changed, then let is needed. If the variable value will not change, then const is needed.
What is the syntax for writing a template literal?
Backticks instead of quotes, ${ } for variables/expressions
What is “string interpolation”?
substituting part of the string for the values of variables or expressions
What is destructuring, conceptually?
A syntax that provides an alternative way to assign properties of an object to variables
What is the syntax for Object destructuring?
let { firstName: fname, lastName: lname } = person;
let { firstName, lastName } = person;
What is the syntax for Array destructuring?
let [x, y, z] = arrayName;
How can you tell the difference between destructuring and creating Object/Array literals?
The name of the Object/Array literal is on the left side of the assignment operator when creating, and it’s on the right side when destructuring.
What is the syntax for defining an arrow function?
( ) => {
}
When an arrow function’s body is left without curly braces, what changes in its functionality?
The result of the expression will be returned
How is the value of this determined within an arrow function?
an arrow function captures the this value of the enclosing context instead of creating its own this context