es6 Flashcards
What is a code block? What are some examples of a code block?
defined statements that are executed together
{anything inside curly braces}
What does block scope mean?
A block scoped variable means that the variable defined within a block will not be accessible from outside the block
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
let can be redeclared but const can’t
Why is it possible to .push() a new value into a const variable that points to an Array?
we can change the arrays elements but we can’t change the arrays variable name
How should you decide on which type of declaration to use?
depending on weather you plan on mutating that variable or not
What is the syntax for writing a template literal?
``
What is “string interpolation”?
adding variables to strings ${}
What is the syntax for defining an arrow function?
()=>{}
When an arrow function’s body is left without curly braces, what changes in its functionality?
you can only have one expression not multiple also it automatically returns the result without the return statement
How is the value of this determined within an arrow function
its value within the arrow function is determined by the surrounding scope
example::
To fix this, you assign the this value to a variable that doesn’t shadow inside the anonymous function as follows:
What is destructuring, conceptually?
extracting data from arrays or objects
What are the three states a Promise can be in?
pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed
How do you handle the fulfillment of a Promise?
then
How do you handle the rejection of a Promise?
catch or then with a second callback funtion to handle the rejection