ES6 Flashcards
What is a code block? What are some examples of a code block?
Surrounded by brackets with code written inside. Functions, loops, if conditionals
What does block scope mean?
Only available within that block
What is the scope of a variable declared with const or let?
Block-scope
What is the difference between let and const?
Let - can be reassigned. Const - cannot be reassigned. “=”
Why is it possible to .push() a new value into a const variable that points to an Array?
We are not reassigning the value
How should you decide on which type of declaration to use?
You let if you need the value to change (reassigned) and const if the value will always be the same.
What is the syntax for writing a template literal?
Using backticks around the string and a dollar sign with curly brace around the variable
What is “string interpolation”?
Substituting part of a string with variables.
What is destructuring, conceptually?
To take pieces of a more complex structure (elements from array, prop from obj) and assign them to variables. Assigning properties of an object or an array to individual variables
What is the syntax for Object destructuring?
const object with key value pairs assigned to a variable
What is the syntax for Array destructuring?
const with square brackets with variable names with an assignment operator and the array it’s coming from
How can you tell the difference between destructuring and creating Object/Array literals?
Objects or array is on the left of the assignment operator for destructuring while objects or array is on the right of the assignment operator when creating an object/array literal
What is the syntax for defining an arrow function?
Variable keyword, var name, parameters (necessary if zero parameter, optional if one parameter and necessary if more than one parameter), arrow, curly braces (only if a statement)
When an arrow function’s body is left without curly braces, what changes in its functionality?
You can only have one line of code. Has to be an expression.
How is the value of ‘this’ determined within an arrow function?
Is based on when the arrow function is defined. The value of ‘this’ in its parent code block. If the parent is an arrow function as well, it keeps going up.