JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
block of code inside curly braces
What does block scope mean?
only accessible inside the block
What is the scope of a variable declared with const or let?
block scoped variables
What is the difference between let and const?
const = x change
let = can change
Why is it possible to .push() a new value into a const variable that points to an Array?
not reassigning it, just changing its value
How should you decide on which type of declaration to use?
if reassignment is needed use let /
otherwise use const
What is the syntax for writing a template literal?
using backticks ` `
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
taking properties of object out and assigning them to variables
What is the syntax for Object destructuring?
const book1 = { title: ‘Goodnight Punpun’, author: ‘Inio Asano’, libraryID: 3353 };
const { title, author, libraryID } = book1;
What is the syntax for Array destructuring?
const [x, y, z] = library;
How can you tell the difference between destructuring and creating Object/Array literals?
creating : variable left hand side
destructuring: variable right hand side
What is the syntax for defining an arrow function?
parameters => expression/return statement
When an arrow function’s body is left without curly braces, what changes in its functionality?
returns the result of the expression
How is the value of this determined within an arrow function?
Unlike an anonymous function, an arrow function captures the this value of the enclosing context instead of creating its own this context.
const bar = (n) => 2 * n
same as
function bar (n) {
return 2 * n
};
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 is “syntactic sugar”?
Designed to make things easier to read or to express. It 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 the typeof an ES6 class?
Object
Describe ES6 class syntax.
class Person {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
What is “refactoring”?
restructuring the format to make it more readable