ES6 JS Flashcards
What is a code block? What are some examples of a code block?
The code block is a location where we write codes between the curly braces.
{}
What does block scope mean?
It restricts the variable that is declared inside the specific block from being accessed from outside of the block
What is the scope of a variable declared with const or let?
blocked-scope
What is the difference between let and const?
You can change the value assigned to the let
keyword while const you cannot.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because you are not reassigning a different array to the const variable, you are simply adding a value to the same array
The object is still mutable when it’s assigned to a variable so you can add data to it
How should you decide on which type of declaration to use?
If you need to reassign values to the variable, then you should use let
What is the syntax for writing a template literal?
${variable}
What is “string interpolation”?
ability to substitute part of the string for the values of variables or expressions
substitute a variable with a string
What is destructuring, conceptually?
JS expression that makes it possible to unpack elements from arrays or properties from objects, into distinct variables
It’s how you get object properties or array elements into one line
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
What is the syntax for Array destructuring?
let [x, y, z] = variableName
How can you tell the difference between destructuring and creating Object/Array literals?
you have the variable name to the left of the ‘=’ operator when creating object/array literals. Whereas, the variable name is on the right when destructuring.
What is the syntax for defining an arrow function?
parameter => expression
param => { statement }
When an arrow function’s body is left without curly braces, what changes in its functionality?
It has an implicit return
You will need a curly braces when you have multiple lines of statement with a return statement
How is the value of this determined within an arrow function?
parent’s code block and is being determined at definition time