ES6 Flashcards
What is a code block? What are some examples of a code block?
A series of grouped code statements in curly braces. The body of a for loop, while loop, if statement, function.
What does block scope mean?
Variables declared within a containing code block are only accessible within that containing block.
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
A let variable can be reassigned another value after declaration
A constant can not be reassigned another value after declaration
Why is it possible to .push() a new value into a const variable that points to an array?
Although a constant can not be reassigned another value, if it points to an array, that array can be manipulated. Since the constant still points to the same array, reassignment is not occurring.
How should you decide on which type of declaration to use?
If you plan on never reassigning another value, then declare a constant.
If you plan on reassigning another value, then declare a let variable.
What is destructuring, conceptually?
- breaking up the structure
- in JavaScript, it is a shortcut for assigning array values and object properties to variables
What is the syntax for Object destructuring?
variable keyword followed by opening curly brace, property name (with optional colon and variable name), closing curly brace, assignment operator, and object name let { firstName: fname, lastName: lname } = person;
What is the syntax for Array destructuring?
variable keyword followed by opening bracket, variable names in indexed order, closing bracket, assignment operator, array name
let [x, y, z] = arrayName
How can you tell the difference between destructuring and creating Object/Array literals?
In destructuring, [] and {} are on the left hand side of the assignment operator and the name of the array or object is on the right hand side
What is the syntax for writing a template literal?
backtick, string, placeholder expressions, backtick
Fifteen is ${a + b} and not ${2 * a + b}.
What is “string interpolation”?
replacing placeholders with values in a template literal
What is the syntax for defining an arrow function?
( ) => { }
parameter (parenthesis if more than one parameter), followed by equal sign/arrow, followed by expression (optional curly braces/ return statement)
When an arrow function’s body is left without curly braces, what changes in its functionality?
It returns the result of the expression without a return statement
How is the value of ‘this’ determined within an arrow function?
It comes from the outer scope of its container in its definition, since it does not have its own reference to ‘this’ at call time like other functions