ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are denoted with curly brace brackets. Some examples include function code blocks, conditional statements, loop code blocks.
What does block scope mean?
The variable is only accessible within that code block.
Variables declared using var are accessible outside of a code block except for function code blocks
What is the scope of a variable declared with const or let?
Block-scoped
What is the difference between let and const?
‘let’ can be reassigned while ‘const’ cannot
Why is it possible to .push() a new value into a const variable that points to an Array?
The variable has the same memory address as its value, referring to a certain array. The array is mutable but the location in memory remains constant
The name binding cannot be changed
The array remains constant, not the elements within it
How should you decide on which type of declaration to use?
Rather than use ‘var’, use ‘const’ or ‘let’. If the variable is going to be changed from its initial value, use ‘let’
usually default to ‘const.’ If there is problems in the future, change to ‘let’
What is the syntax for writing a template literal?
backtick $ { } backtick
What is “string interpolation?”
Substituting parts of a string with the values of variables or expressions
What is destructuring, conceptually?
Taking the properties of an object and assigning them to multiple variables in one go
What is the syntax for Object destructuring?
const thing = {
this: 1,
that: 2,
};
const { this, that } = thing;
What is the syntax for Array destructuring?
const things = [
{this: 1, that 1},
{this: 2, that 2}
]
const [thing2, thing3] = things
How can you tell the difference between destructuring and creating Object/Array literals?
With destructuring, curly brackets on the left hand side of equal sign
With creating, curly brackets on the right hand side of equal sign
What is the syntax for defining an arrow function?
(parameter 1, parameter 2) => {code block}
When an arrow function’s body is left without curly braces, what changes in its functionality?
The arrow function returns value of the expression of the body without the curly brace (an implicit return)
How is the value of ‘this’ determined within an arrow function?
While regular function syntax will create a new function that creates its own this
, arrow functions do not create their own this
. Instead, it will be lexically scoped, so it will find the this
for the context that it is within
They don’t create their own this
binding
Value of this
is defined at definition time, not at call time (which is the case for traditional ES5 functions)
If you can’t see where it’s being called, this
might be referring to the global window