ES6 Flashcards

1
Q

What is a code block? What are some examples of a code block?

A

the opening and closing of curly braces { } (denoted by curly braces). for, if, while are examples of code block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does block scope mean?

A

the variable defined within a block (code block) will not be accessible from outside the block (code block)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the scope of a variable declared with const or let?

A

they are blocked-scope. while var function-scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between let and const?

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How should you decide on which type of declaration to use?

A

use let if the variable is reassigned at any time of the code, else use const if not being reassigned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax for writing a template literal?

A

by wrapping text in backticks ( string string ${'yoon'.toUpperCase()} )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is destructuring, conceptually?

A

extracting elements from arrays or properties from objects, and assigning them to different variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the syntax for Object destructuring?

A

const { property: theNewVariable, property: theNewVariable, propKey(if want same variable) } = object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the syntax for Array destructuring?

A

const [ variable, variable] = array;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax for defining an arrow function?

A

var, let, const(keyword) variable = (param(s)) => { statements }

(param1, param2) => {
return;
};

param => expression;

() => expression;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

without the curly braces { } the arrow function has an implicit return. evaluated as an expression and returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How is the value of this determined within an arrow function?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the three states a Promise can be in?

A

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

17
Q

How do you handle the fulfillment of a Promise?

A

use the then() method, it returns a promise.
Promise.then( (value) => {
console.log(value);
});

pass in a callback function in the then(callback);

18
Q

How do you handle the rejection of a Promise?

A

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.

19
Q

What is Array.prototype.filter useful for?

A

it filters down to just the elements from the given array that pass the test implemented by the provided function

20
Q

What is Array.prototype.map useful for?

A

creates a new array populated with the results of calling a provided function on every element in the calling array

21
Q

What is Array.prototype.reduce useful for?

A

is to return the sum of all the elements in an array,

22
Q

What is “syntactic sugar”?

A

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.

23
Q

What is the typeof an ES6 class?

A

function

24
Q

Describe ES6 class syntax.

A
class ClassName {
    (optional) constructor(param, param2) {
        this.param = param;
        this.param2 = param2;
    }
getMethod() {
    return this.method() ex this.name
} }
25
Q

What is “refactoring”?

A

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

26
Q

How are ES Modules different from CommonJS modules?

A

commonJS = provides modules

ES Modules = dedicated keyword for import and export

27
Q

What kind of modules can Webpack support?

A

CommonJS Modules, AMD modules, and ECMAScript Modules