ES6 Flashcards
What is a code block? What are some examples of a code block?
- Portions of code denoted by curly braces {}.
- Some examples are if/else, for, while, try/catch.
What does block scope mean?
Variables declared within that code block can’t be accessed by code outside of the block
What is the difference between var and let?
Var adds the variable to the property list of the global object (window for browsers) —> let does not.
What is the scope of a variable declared with const or let?
They’re both block scoped.
What is the difference between const and let?
- Block-scoped variables assigned by const keyword can not be reassigned.
- You also have to initialize a value to the variable declared by const —> you don’t have to immediately with let.
Why is it possible to .push() a new value into a const variable that points to an array?
The array is not immutable, it can change. It’s just the variable that stores the array that can’t be changed.
How should you decide on which type of declaration to use?
Unless you’re positive you’re going to change the memory pointer, use const.
What is the syntax for writing a template literal?
Use backticks (string-goes-here
)
What is string interpolation?
The ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
Taking an array or object and assigning some OR all values to corresponding variables
What is the syntax for Object destructuring?
Let { property1: variable1, property2: variable2 } = object
What is the syntax for Arrray destructuring?
[a, b, c] = [value1, value2, value3] OR let [x, y, z] = getScores( )
•How can you tell the difference between destructuring and creating Object / Array literals?
The variables are always wrapped in an object / array and the sides are swapped.
What is the syntax for defining an arrow function?
Const functionName = (parameters) => {code block w/optional return}
If an arrow function only has one parameter, we can…
Remove the parenthesis entirely