ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are denoted by culry braces { }
The show up in conditionals and functions.
What does block scope mean?
It means that the var/let and its value is only effective within that code block that it is declared in.
What is the scope of a variable declared with const or let?
they are block-scoped, as they are NOT global and cannot be accessed outside of the block they are contained in
What is the difference between let and const?
const CANNOT be reassigned while let can be mutable
Why is it possible to .push() a new value into a const variable that points to an Array?
Because you can still ADD values to the object, but you cannot reassign the value. So push() is fine, but
How should you decide on which type of declaration to use?
Whether or not the variable needs to be reassigned or not. if it doesnt, then const would be the choice you should use.
What is the syntax for writing a template literal?
let string = ` the text within the string `
instead of using quotes for strings, we are using backticks. This will let the user have multiline strings and be able to use any quotations freely’
What is “string interpolation”?
The ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
assigns the properties of an object to variables with the same names by default, unless stated otherwise.
What is the syntax for Object destructuring?
let { object.property1, object.property2…. etc} = object.
What is the syntax for Array destructuring?
let [x, y, z] = array.
This will set the variables of x, y, z to the first 3 indexes of the array.
If the array is < 3, the ‘empty’ variables will be undefined.
If the array is > (the # of listed variables), all argumenst AFTER the last listed variable will be disregarded.
it can use [x, y, … arg] to set all the values after y to another string.
How can you tell the difference between destructuring and creating Object/Array literals?
object destructuring is mentioning the property the object that contains.
array destructuring only names the new variables that is ‘coming out’
What is the syntax for defining an arrow function?
(x,y) =>
this states the parameters of the function and what the function is going to do
When an arrow function’s body is left without curly braces, what changes in its functionality?
without curly braces, it can only use an expression.
WITH curly braces, you can use a statement and an expression.
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.