ES6 Flashcards
What is a code block? What are some examples of a code block?
section of code enclosed within { }, ex: function, conditional, loop
What does block scope mean?
a value is only available within a certain 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 variables can be reassigned, const variables can’t
Why is it possible to .push( ) a new value into a const variable that points to an Array?
you can’t reassign a const variable, but you can change the value of the variable
How should you decide on which type of declaration to use?
if a variable needs to be a reassigned, use let, otherwise use const
What is the syntax for writing a template literal?
Use backticks instead of quotes
What is “string interpolation”?
replacing substitutions with the values of the variables and expressions
What is destructuring, conceptually?
taking apart an object or array and assigning the parts to different variables
What is the syntax for Object destructuring?
let { prop1: var1, prop2: var2} = 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?
it’s destructuring if the brackets are on the left of the assignment operator, creating if the brackets are on the right
What is the syntax for defining an arrow function?
( parameters ) => {statements};
When an arrow function’s body is left without curly braces, what changes in its functionality?
without the curly braces, you can only have one expression
How is the value of this determined within an arrow function?
the value of this is determined by the value of this in its containing code block