ES6 Flashcards
What is a code block? What are some examples of a code block?
A code block is code contained between a pair of curly braces. E.g. { const a = 5; console.log(a); }
What does block scope mean?
A variable with block scope is accessible only within the code block it was declared in.
What is the scope of a variable declared with const or let?
Block scope.
What is the difference between let and const?
const variables cannot be reassigned, let variables can.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because the variable address is not being changed.
How should you decide on which type of declaration to use?
Use const unless you need to reassign let.
What is the syntax for writing a template literal?
Write string in between backticks like this
What is “string interpolation”?
Substituting a piece of the string for results of expressions.
What is destructuring, conceptually?
Taking the value of a property from an object and assigning it to a variable.
What is the syntax for Object destructuring?
const { variable } = objectExample;
What is the syntax for Array destructuring?
const [one, two, three] = [1, 2, 3];
How can you tell the difference between destructuring and creating Object/Array literals?
In destructuring, the brackets are on the left of the assignment operator, whereas when Object/Array literals are being created the brackets are on the right.
What is the syntax for defining an arrow function?
parameter => code;
e.g. x => x + 2;
Add parentheses if more than one parameter and curly braces if more than one line of code.
When an arrow function’s body is left without curly braces, what changes in its functionality?
There can only be one expression and no statements.
How is the value of this determined within an arrow function?
In an arrow function, this captures the this value of its enclosing context during definition instead of creating its own during call time.