ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are indicated by curly braces and it helps to declare data as local
What does block scope mean?
Does not create property on global window object. Declaring a variable inside any code block shown by curly brackets and only lives and acts inside.
What is the scope of a variable declared with const or let?
They are blocked-scope compared to var which is global scope or local scope
What is the difference between let and const?
const cannot be reassigned and variable reference cannot change while let can be. Therefore, const needs to be always assigned a value when declared
Why is it possible to .push() a new value into a const variable that points to an Array?
You could update the values but cannot change the reference points
How should you decide on which type of declaration to use?
If you want to reassign variables then use let and if variables don’t need to be changed but just the value you can use const
What is the syntax for writing a template literal?
` string content ` - use back-ticks instead of quotes and to substitute a variable and an expression: ${variableName}
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
unpacking values and assigning variables
What is the syntax for Object destrucuring?
const {property1: variable1, property2: variable2} = object;
What is the syntax for Array destructuring?
const/let [variable1, variable2, variable3] = array
How can you tell the difference between destructuring and creating Object/Array literals?
Destructuring - you’re not adding any new values to the object or an array and whether assigned variables to existing object/array literals. Destructuring also have brackets go on the lefthand side while creating is on the righthand side.
What is the syntax for defining an arrow function?
const variable = (x,y) => return statement
When an arrow function’s body is left without curly braces, what changes in its functionality?
No curly braces will result in implicit return
How is the value of this determined within an arrow function?
normal this is determined by calltime, but in arrow function you look at where the function is defined or definition time