ES 6 Flashcards
What is a code block? What are some examples of a code block?
Code block is pair of curly braces used to group zero or more statements. Some examples are if else statements, for loops, do while, while loops
What does block scope mean?
variables only exist within corresponding code block.
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
the blocked scoped variables declared using const cannot be reassigned. Let can be reassigned.
Why is it possible to .push() a new value into a const variable that points to an Array?
We cannot reassign the variable to another array but const still allows values of the array to be changed.
How should you decide on which type of declaration to use?
always use const. If const cannot be used, use let.
What is the syntax for writing a template literal?
back tick, dollar sign, curly braces ${}
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
What is destructuring, conceptually?
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables
What is the syntax for Object destructuring?
declaration, curly braces, property name.
let { firstName: fname, lastName: lname } = person;
What is the syntax for Array destructuring?
declaration, square brackets, property name.
let [x, y, z] = getScores();
How can you tell the difference between destructuring and creating Object/Array literals?
instead of values being pulled out of an array, properties (keys) and their values can be pulled out of an object. Object we use curly braces and arrays we use square brackets.
What is the syntax for defining an arrow function?
let add = (x, y) => x + y;
When an arrow function’s body is left without curly braces, what changes in its functionality?
if you use the block syntax, you need to specify the return keyword, if not we do not need the return keyword. (no curly braces = implicit return
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.