ES6 Flashcards
What is a code block? What are some examples of a code block?
code blocks are denoted by curly braces { }
ex: if, for, while
What does block scope mean?
the variable inside the block is a new variable and it shadows the variable declared at the top of the script
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
const - denotes that a variable is a constant and can’t be reassigned
let - can be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
the actual value to which the const variable reference is not immutable
How should you decide on which type of declaration to use?
if the variable will be reassigned, use let
What is the syntax for writing a template literal?
wrapping your text in backticks and writing expressions inside ${ }
What is “string interpolation”?
replacing placeholders with values in a string literal
What is destructuring, conceptually?
extracting data from arrays or objects into smaller parts
What is the syntax for Object destructuring?
let / const keyword {
propertyOfObj: nameOfVariable
} = object
What is the syntax for Array destructuring?
let / const keyword [varName1, varName2, etc] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
creating - the name of the variable comes first
destructuring - curly brace / square bracket comes first
What is the syntax for defining an arrow function?
(parameter) => {code block}
When an arrow function’s body is left without curly braces, what changes in its functionality?
without curly braces, it can only be a single expression (an implicit return), with curly braces, it needs a return keyword
How is the value of this determined within an arrow function?
an arrow function doesn’t have it’s own this value and captures the this value of the lexical scope (the outer function)