JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
code block is a group of zero or more statements to be executed once it meets a condition. Examples: if else, for, do while, while, try catch.
What does block scope mean?
The scope created with a pair of curly braces
What is the scope of a variable declared with const or let?
blocked-scope
What is the difference between let and const?
let can be reassigned. const cannot be reassigned.
Why is it possible to .push() a new value into a const variable that points to an Array?
you’re not changing a property(key) value pair, you’re adding a new one onto it.
How should you decide on which type of declaration to use?
if you know you need to change variable later, use let, otherwise use const.
What is the syntax for writing a template literal?
let simple = this is a template literal
; (text wrapped in backticks)
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions with special block ${variable_name}
What is destructuring, conceptually?
It assigns properties of an object to individual variables.
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
if same name for property and variable, more concise code
let { firstName, lastName } = person;
What is the syntax for Array destructuring?
let [x, y, z] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
variable of the source object/array is to the right of the assignment operator for destructuring and to the left is the values to unpack from the sourced variable.
for creating a literal, const/let is to the left of the array/object variable name.
What is the syntax for defining an arrow function?
param => {
statements
}
(param1, paramN) => {
statements
}
When an arrow function’s body is left without curly braces, what changes in its functionality?
With this syntax, the arrow function has an implicit return. No return statement, has to be an expression.
without the curly braces, you can only have one expression
How is the value of this determined within an arrow function?
the value of this is determined by the value of “this” in its containing code block
The arrow function retains the value of the this
In normal functions this is assigned at the value of call time
In arrow function this is being assigned at the time of definition