JS ES6 Flashcards
What is a code block? What are some examples of a code block?
A code block is the space between curly braces. Examples include the code block within function definitions. The code block of for loops and while loops.
What does block scope mean?
Block scope begins at the first curly brace. Any variables defined, or reassigned within block scope are only accessible within that block scope.
What is the scope of a variable declared with const or let ?
Their scope is block scope.
What is the difference between let and const ?
let can be reassigned, const can not be. const is a read only reference. let doesn’t have to be initialized to a value when declared… const does.
Why is it possible to .push() a new value into a const variable that points to an Array ?
because a const variable is read-only… the actual value referenced isn’t immutable
How should you decide on which type of declaration to use?
the declaration you use should be determined by whether or not a variable is intended to be reassigned or not
What is the syntax for writing a template literal?
strings and/or variables written between backticks ( ` ` )
What is string interpolation?
being able to substitute part of a string with values of variables or expressions
What is destructuring, conceptually?
The mass assignment of object properties / array values to variables.
What is the syntax for Object destructuring?
let { objProp1: var1, objProp2: var2 } = mainObj;
What is the syntax for Array destructuring?
let [ var1, var2, var3 ] = exArray;
How can you tell the difference between destructuring and creating Object/Array literals?
the side on which the curly braces/square brackets are on
What is the syntax for defining an arrow function ?
(p1,p2…) => {
}
When an arrow function’s body is left without curly braces, what changes in its functionality?
it becomes an implicit return value
How is the value of this determined within an arrow function?
this isn’t defined when the arrow function is called, it’s inherited from the parent scope
What are the three states a Promise can be in?
pending, fulfilled, and rejected
How do you handle the fulfillment of a Promise?
you call the then() method of the Promise and pass whatever you would like done on the fulfillment
How do you handle the rejection of a Promise?
you call the catch() method of the Promise and pass whatever you would like done on the fulfillment
What is Array.prototype.filter useful for ?
it’s useful for locating and keeping values based off of some criteria that you provide. it’s a loop and conditional in one function
What is Array.prototype.map useful for?
it’s useful for doing an expression on each index of an Array
What is Array.prototype.reduce useful for?
combining the elements of an entire array into a single value
What is syntactic sugar?
is syntax that is designed to make things easier to read or to express
What is the typeof an ES6 class?
function
Describe ES6 class syntax
keyword class and then the name you want your class to be capitalized