ES6 Flashcards
What is a code block? What are some examples of a code block?
A block of code that contains statements that you want to execute together contained within curly braces {}
Function, conditional, loop code block
What does block scope mean?
Can’t access variables within the block, outside of the block
What is the scope of a variable declared withconstorlet?
Block-scoped
What is the difference betweenletandconst?
Let: mutable, not initialized to any value, and not attached to the global object as a property
Const: read-only reference, can’t be reassigned (immutable), need to initialize the value to the variable declared, constant identifiers are in uppercase
Why is it possible to.push()a new value into aconstvariable that points to anArray?
An array is a special type of object and the property of aconstobject can be change but it cannot be change to reference to thenewobject
Not changing the variable name binding, mutating the content of the array which are mutable
How should you decide on which type of declaration to use?
Use const until you need to reassign the value of the variable, then use let
What is the syntax for writing a template literal?
String must be wrapped with backticks ( string
)
Embedded JavaScript expressions wrapped with ‘$’ and ‘{}’, ${expression}
If string contains a backpack, it must be escaped using a backslash ( \ )
Allows for multi-line strings, string interpolations with embedded expressions, and tagged templates
What is “string interpolation”?
Insert, or interpolate, variables into strings using template literals. Use placeholders of the form ${expression} to perform substitutions for embedded expressions
What is destructuring, conceptually?
Unpack values from arrays, or properties from objects, into distinct variables
What is the syntax forObjectdestructuring?
const { var1, var2: varAlias2 } = obj
Use (:) colon to rename variable
What is the syntax forArraydestructuring?
const [var1, var2, var3] = arr
Use (,) to skip elements in array
How can you tell the difference between destructuring and creatingObject/Arrayliterals?
When destructing, the curly or square brackets appear on the left of the assignment operator, however when creating object or array literals the brackets appear on the right
What is the syntax for defining an arrow function?
(param1, param2) => {
return;
};
param => exp; // implicit return
() => exp;
When an arrow function’s body is left without curly braces, what changes in its functionality?
Function body evaluated as an expression and implicit return
How is the value ofthisdetermined within an arrow function?
Arrow functions don’t have their own bindings to this; have lexical scoping to this context. Takes this from the enclosing function, value of this it determined when the function is defined.
(Versus ES5 function definition, value of this is determined when the function is called.)
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((value) => { /* fulfillment handler */ })
How do you handle the rejection of a Promise?
.then((reason) => { /* rejection handler */ })
What isArray.prototype.filteruseful for?
Creates a shallow copy of a portion of a give array, filtered down to just the elements from the given array that past the test implemented by the provided function
What isArray.prototype.mapuseful for?
Creates a new array populated with the results of calling a provided function on every element in the calling array
What isArray.prototype.reduceuseful for?
Takes all of the elements in an array and reduces them into a single value
What is “syntactic sugar”?
Syntax within the programming languages that is designed to make things easier to read or to express. Makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.
What is thetypeofan ES6 class?
function
Describe ES6 class syntax.
class className { constructor(parameter) { // constructor code block; } method() { // method code block; } }
What is “refactoring”?
The process of restructuring existing computer code - changing the factoring - without changing its external behavior. It intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality.
How are ES Modules different from CommonJS modules?
ES Modules is the standardized module system for JavaScript, while CommonJS modules is the default Node.js Module System
ES Modules is the standardized module system for JavaScript, while CommonJS modules is the default Node.js Module System
ES Modules use import and export, CommonJS use require() and module.export, both have different syntax.
What kind of modules can Webpack support?
ECMAScript modules, CommonJS modules, and AMD modules.