ES6 Flashcards
What is a code block? What are some examples of a code block?
Surrounded by brackets with code written inside. Functions, loops, if conditionals
What does block scope mean?
Only available within that 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 reassigned. Const - cannot be reassigned. “=”
Why is it possible to .push() a new value into a const variable that points to an Array?
We are not reassigning the value
How should you decide on which type of declaration to use?
You let if you need the value to change (reassigned) and const if the value will always be the same.
What is the syntax for writing a template literal?
Using backticks around the string and a dollar sign with curly brace around the variable
What is “string interpolation”?
Substituting part of a string with variables.
What is destructuring, conceptually?
To take pieces of a more complex structure (elements from array, prop from obj) and assign them to variables. Assigning properties of an object or an array to individual variables
What is the syntax for Object destructuring?
const object with key value pairs assigned to a variable
What is the syntax for Array destructuring?
const with square brackets with variable names with an assignment operator and the array it’s coming from
How can you tell the difference between destructuring and creating Object/Array literals?
Objects or array is on the left of the assignment operator for destructuring while objects or array is on the right of the assignment operator when creating an object/array literal
What is the syntax for defining an arrow function?
Variable keyword, var name, parameters (necessary if zero parameter, optional if one parameter and necessary if more than one parameter), arrow, curly braces (only if a statement)
When an arrow function’s body is left without curly braces, what changes in its functionality?
You can only have one line of code. Has to be an expression.
How is the value of ‘this’ determined within an arrow function?
Is based on when the arrow function is defined. The value of ‘this’ in its parent code block. If the parent is an arrow function as well, it keeps going up.
What are the three states a Promise can be in?
Pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
then()
How do you handle the rejection of a Promise?
catch()
What is Array.prototype.filter useful for?
To find things within an array
What is Array.prototype.map useful for?
To apply a transformation to each element in an array
What is Array.prototype.reduce useful for?
To getting a single value from combining elements from an array
What is “syntactic sugar”?
Syntax within a programming language that makes things easier to read or to express.
What is the typeof an ES6 class?
Function
Describe ES6 class syntax
Keyword class followed by the name of the class with a code block. A constructor in the function (optional) with methods below it.
What is “refactoring”?
The process of restructuring existing code without changing its external behavior
How are ES Modules different from CommonJS modules?
ES module syntax is more compact and can export multiple things. Keywords are different - import/export vs require. Static (ES Module - it will look at the code and remove any unused portions) vs dynamic (CommonJS module). ES6 is ‘official’
What kind of modules can Webpack support?
ECMAScript, CommonJS and AMD modules.