JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
Stuff between curly braces. Functions, loops, conditionals.
What does block scope mean?
anything declared inside a codeblock, stays inside the codeblock.
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
you can reassign a let variable but not a const variable.
Why is it possible to .push() a new value into a const variable that points to an Array?
the array values can be changed, but the variable cannot be reassigned.
How should you decide on which type of declaration to use?
If you are sure you will not need to reassign a variable, use const, otherwise use let. If you are unsure, use const, and change it later if you find out you do need to reassign it.
What is the syntax for writing a template literal?
Using backticks and ${EXPRESSION}
What is “string interpolation”?
writing strings with substitutions.
What is destructuring, conceptually?
unpacking values from arrays, or properties from objects, into distinct variables.
What is the syntax for Object destructuring?
const { objProperty: newVariable, objProperty: newVariable, objProperty: newVariable, etc } = obj;
What is the syntax for Array destructuring?
const [newVariable, newVariable, newVariable, etc] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
The brackets or curly braces come before the assignment operator.
What is the syntax for defining an arrow function?
let functionName = (params) => { code block };
When an arrow function’s body is left without curly braces, what changes in its functionality?
it will return the expression after the =>
How is the value of this determined within an arrow function?