JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
Code inside curly braces, like a function or if block
What does block scope mean?
Scoped inside of a code block. Not accessible outside the block.
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
let is allows re-assignment. const does not allow re-assignment.
Why is it possible to .push() a new value into a const variable that points to an Array?
The address is immutable, but the object the address refers, too, is not. Therefore the object can be modified unless deep freezed.
How should you decide on which type of declaration to use?
If you intend to re-assign the value. Const protects the variable from being re-assigned.
What is the syntax for writing a template literal?
${variable_name inside back ticks
What is “string interpolation”?
The ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
Assigning properties of an object or elements of an array to individual variables.
What is the syntax for Object destructuring?
{ key1, key2, key3 } = obj
What is the syntax for Array destructuring?
[ var1, var2] = array
How can you tell the difference between destructuring and creating Object/Array literals?
destructoring is on the left side of the = sign, creating is on the right side
What are the three states a Promise can be in?
pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
then clause
How do you handle the rejection of a Promise?
catch clause