ES6 Flashcards
What is a code block? What are some examples of a code block?
the opening and closing of curly braces { } (denoted by curly braces). for, if, while are examples of code block.
What does block scope mean?
the variable defined within a block (code block) will not be accessible from outside the block (code block)
What is the scope of a variable declared with const or let?
they are blocked-scope. while var function-scope.
What is the difference between let and const?
variable declared with a const
won’t be reassigned read-only reference. variable declared with a let
may be reassigned, mutable (such as a counter in a loop, or a value swap in an algorithm.)
Why is it possible to .push() a new value into a const variable that points to an Array?
method .push() does not reassign the array. in const adding/removing elements is allowed since it’s not a reassignment. push() is mutation same as pop etc.
How should you decide on which type of declaration to use?
use let if the variable is reassigned at any time of the code, else use const if not being reassigned.
What is the syntax for writing a template literal?
by wrapping text in backticks ( string string ${'yoon'.toUpperCase()}
)
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
extracting elements from arrays or properties from objects, and assigning them to different variables.
What is the syntax for Object destructuring?
const { property: theNewVariable, property: theNewVariable, propKey(if want same variable) } = object
What is the syntax for Array destructuring?
const [ variable, variable] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
It is located on the left side of the assignment operator
when creating a object/array literals, a variable name is followed by the var, let, const keyword. however in destructuring, object literal or array literal is followed by those keywords.
What is the syntax for defining an arrow function?
var, let, const(keyword) variable = (param(s)) => { statements }
(param1, param2) => {
return;
};
param => expression;
() => expression;
When an arrow function’s body is left without curly braces, what changes in its functionality?
without the curly braces { } the arrow function has an implicit return. evaluated as an expression and returned.
How is the value of this determined within an arrow function?
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
can only go from pending to resolved OR pending to rejected
How do you handle the fulfillment of a Promise?
use the then() method, it returns a promise.
Promise.then( (value) => {
console.log(value);
});
pass in a callback function in the then(callback);
How do you handle the rejection of a Promise?
the catch() method, it returns a promise and deals with rejected cases only.
Promise.catch( (error) => {
console.error( error.message );
});
look up Error.prototype.message on MDN, message property is a human-readable description of the error.
What is Array.prototype.filter useful for?
it filters down to just the elements from the given array that pass the test implemented by the provided function
What is Array.prototype.map useful for?
creates a new array populated with the results of calling a provided function on every element in the calling array
What is Array.prototype.reduce useful for?
is to return the sum of all the elements in an array,
What is “syntactic sugar”?
is syntax within a programming language that is designed to make things easier to read or express or write. makes the language sweeter for human use: expressed more clearly, concisely, in alternative style that some may prefer.
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class ClassName { (optional) constructor(param, param2) { this.param = param; this.param2 = param2; }
getMethod() { return this.method() ex this.name } }
What is “refactoring”?
is the process of restructuring existing code, chaging the factoring, without changing its external behavior. is intended to improve the design, structure, and/or implementation of the software while preserving its functionality. code does the exact same thing, but easier to read/understand, also easier to make changes to as the code grows
How are ES Modules different from CommonJS modules?
commonJS = provides modules
ES Modules = dedicated keyword for import and export
What kind of modules can Webpack support?
CommonJS Modules, AMD modules, and ECMAScript Modules