JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
Stuff between curly braces. Functions, loops, conditionals.
What does block scope mean?
anything declared inside a codeblock, stays inside the codeblock.
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
you can reassign a let variable but not a const variable.
Why is it possible to .push() a new value into a const variable that points to an Array?
the array values can be changed, but the variable cannot be reassigned.
How should you decide on which type of declaration to use?
If you are sure you will not need to reassign a variable, use const, otherwise use let. If you are unsure, use const, and change it later if you find out you do need to reassign it.
What is the syntax for writing a template literal?
Using backticks and ${EXPRESSION}
What is “string interpolation”?
writing strings with substitutions.
What is destructuring, conceptually?
unpacking values from arrays, or properties from objects, into distinct variables.
What is the syntax for Object destructuring?
const { objProperty: newVariable, objProperty: newVariable, objProperty: newVariable, etc } = obj;
What is the syntax for Array destructuring?
const [newVariable, newVariable, newVariable, etc] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
The brackets or curly braces come before the assignment operator.
What is the syntax for defining an arrow function?
let functionName = (params) => { code block };
When an arrow function’s body is left without curly braces, what changes in its functionality?
it will return the expression after the =>
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.
How do you handle the fulfillment of a Promise?
.then
How do you handle the rejection of a Promise?
.catch
What does Array.filter do?
What should the callback function return?
returns a truthy or falsey value and if its truthy, add it to the copy.
What is Array.filter useful for?
What does Array.map do?
What should the callback function return?
What is Array.filter useful for?
What does Array.reduce do?
walks through an array and reduces it into a single value.
What action should the callback function perform?
examine the current element, do a computation to it and add it to the accumulated value.
What should the callback function return?
What is Array.reduce useful for?
What are JavaScript classes?
Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are unique to classes.
When would you want to use a class?
If you have data or functionality to encapsulate.
How do you declare a class?
using the class keyword
class NameOfClass {
code block
}
How do you inherit from another class?
using the extends keyword
class NameOfClass extends SuperClass {
code block
}
Why would you want to inherit from another class?
reuse, extend, and modify the behavior defined in other classes
How do you add methods and properties to a class?