ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are a group of statements that need to be executed.
Code blocks are defined using curly braces., such as functions, if/else statements, loops.
What does block scope mean?
The variable defined within the block cannot be accessed outside the block that it was declared in.
also makes a shadow copy of variable that was declared outside block.
What is the scope of a variable declared with const or let?
both const and let are declared as block - scope.
Var variables are not block-scope they are function scope.
What is the difference between let and const?
Let is mutable meaning you can change their values anytime you want.
Const is immutable meaning you can’t reassign them to different values.
You CANNOt reassign a const variable.
Why is it possible to .push() a new value into a const variable that points to an Array?
Even though the variable is a constant, you can change the value of its property.
However, you cannot reassign a different value to the constant.
The values inside the const array can be change, it can add new items to const arrays but it cannot reference to a new array.
How should you decide on which type of declaration to use?
Use let when youre sure that the value of the variable will change.
otherwise use const.
What is the syntax for writing a template literal?
Template literals are enclosed by backtick (`) characters instead of double or single quotes.
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
using template literals you can substitute variables or expressions into a string using the special block which its syntax is ${expression}.
What is destructuring, conceptually?
it lets you extract data from objects or arrays and assigning them to different variables.
Object destructuring assigns the properties of an object to variables with the same names by default.
What is the syntax for Object destructuring?
const { property1, property2 } = obj;
What is the syntax for Array destructuring?
const [ property1, property2] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
Object destructuring uses curly braces while arrays use brackets.
What is the syntax for defining an arrow function?
const varName = (param1, param2) => {whatever statements that need to be executed in the code block};
When an arrow function’s body is left without curly braces, what changes in its functionality?
it returns the result of the expression.
the return is implied if theyres no curly braces, meaning theres only one statement in the code block.
How is the value of THIS determined within an arrow function?
With arrow functions the this keyword always represents the object that defined the arrow function.
it takes the this from the enclosing function. it is determined when an arrow function is defined.
gets its this from its surrounding function.
regular functions gets value of this at call time while arrow functions gets value of this at definition time.