ES6 (JavaScript) Flashcards
What is a code block? What are some examples of a code block?
A group statements between curly braces.
i.e., a function code block or a if statement code block.
What does block scope mean?
Block scope restricts the access to a variable to only within its code block.
What is the scope of a variable declared with const or let?
Blocked scope.
What is the difference between let and const?
Variables declared using let are mutable (can be reassigned).
Variables declared using const are immutable (cannot be reassigned).
Why is it possible to .push() a new value into a const variable that points to an Array?
The const keyword creates a variable that is read-only.
The array assigned to a const variable can be modified, but the const variable itself cannot be assigned a new array or other value.
How should you decide on which type of declaration to use?
Whether the developer intends to reassign a variable.
What is the syntax for writing a template literal?
A string or (optional) JavaScript expressions in between backticks.
What is “string interpolation”?
The ability to substitute part of a string for the values of variables or expressions.
What is destructuring, conceptually?
A (alternative) way to assign properties of an object to variables or assign elements of an array to variables.
What is the syntax for Object destructuring?
The const keyword followed by curly braces. Inside the curly braces is the property of an object and variable name separated by a colon. After the curly brace is an assignment operator followed by the name of the object and semicolon.
What is the syntax for Array destructuring?
The const keyword followed by square brackets. Inside the square brackets are variable names separated by commas. After the square brackets is an assignment operator followed by the name of the array and semicolon.
How can you tell the difference between destructuring and creating Object/Array literals?
Objects use curly braces and arrays use square brackets.
What is the syntax for defining an arrow function?
Parameters separated by commas inside parenthesis (if any/two or more) followed by an arrow. After the arrow, there can either be an expression or an arrow function body that has a return operator then a semicolon.
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without curly braces, the arrow function returns the result of an expression (implicit return expression) instead of returning a value.
How is the value of this determined within an arrow function?
The value of this determined by it’s surrounding code block.
The value of this is determined when the arrow function is defined.