ES6 const & let, template literals, destructuring, and arrow functions Flashcards
What is a code block? What are some examples of a code block?
A code block is a chunk of code inside curly braces
if (conditions) { //code block here }
What does a block scope mean?
Code in a code block can only be referenced by code that is in the code block
What is the scope of a variable declared with const or let?
Block scoped as opposed to function scoped
What is the difference between let and const
let is mutable
const values cannot be re-assigned, they are immutable
Why is it possible to .push() a new value into a const variable that points to an Array?
Variables are objects, objects are mutable
You are updated the index value of an array, but not re-assigning the value of the variable itself
How should you decide on which type of declaration to use?
You should use const when the value of the variable isn’t going to be updated
You should use let when the value of the variable is going to be updated
What is the syntax for writing a template literal?
let name = String content here
Surround a string with backticks
What is string interpolation?
String interpolation allows you to embed variables and expressions in the string.
JavaScript will automatically replace these variables and expressions by their values
${variable}
What is destructing, conceptually?
Taking either properties of an object or indexes of an array to separate them to create specific variables
What is the syntax for Object destructuring?
const { property, property2, property3 } = objectName
What is the syntax for Array destructuring?
const [ variable, variable2, variable3 ] = arrayName
How can you tell the difference between destructuring and creating Object/Array literals?
If the brackets are on the left side of the assignment operator, you are destructuring.
If the brackets are on the right side of the assignment operator, you are creating.
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without curly braces, you can only have a return on to the right of the arrow.
How is the value of this determined within an arrow function?
With an arrow function, it is determined at definition time
What is the syntax for defining an arrow function?
() => line of argument
() => { code block }
(para1, para2) => 1 line of argument
(para1, para2) => { code block }
para => 1 line of argument
para => { code block }