ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are denoted by curly braces. Usually for an if statement, if else statement, for loop, do while loop, while loop, and try catch
What does block scope mean?
Block scope refers to the variable thats declared can only exist within that block only.
What is the scope of a variable declared with const or let?
The scope of const and let are both blocked-scope variables.
What is the difference between let and const?
The difference is that let is mutable while const is a read-only reference.
Why is it possible to .push() a new value into a const variable that points to an Array?
The .push() doesn’t change the variable from an array to another array or something else. It only adds elements inside that array.
How should you decide on which type of declaration to use?
If a variable is not going to need changing, const should be used. If the variable may need its value updated, let is the right way to declare.
What is the syntax for writing a template literal?
The syntax for writing template literal starts with backticks ` and ends with backticks `. Similar to quotes and double quotes.
What is “string interpolation”?
To replace variables and expressions with their values within a string.
What is destructuring, conceptually?
Destructing allows properties or elements inside an array to be assigned to a variable in a quicker way. To be able to pull out what is needed from an entire data structure.
What is the syntax for Object destructuring?
Declare a variable followed by the curly brace. Property names are assigned to variables with the colon sign in between. Followed by a closing curly brace. and that whole code block is assigned to a variable name.
What is the syntax for Array destructuring?
Declare a variable followed by the opening square bracket. Inside are variable names in place of the each object or element in the array. Followed by a closing square bracket and assigned to a variable name.
How can you tell the difference between destructuring and creating Object/Array literals?
Destructuring would have the variable declaration but no variable name yet and the variable name is defined at the end. Creating object and array literals involve having the variable name in the beginning before the curly or square brackets.
What is the syntax for defining an arrow function?
Instead of using the function keyword, there is just the parameters or empty parameter followed by equal sign and the greater than ankle bracket followed by the code block that runs for that function. The code is implied to return the value unless there is curly brackets then the keyword return needs to be used.
When an arrow function’s body is left without curly braces, what changes in its functionality?
The keyword return is implied for the body. If there are multiple expressions to compute, then the return won’t occur.
How is the value of this determined within an arrow function?
The value of this is determined at the time the arrow function is defined.