ES6 Flashcards

1
Q

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

A

A block of code that contains statements that you want to execute together contained within curly braces {}
Function, conditional, loop 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

Can’t access variables within the block, outside of the 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 withconstorlet?

A

Block-scoped

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

What is the difference betweenletandconst?

A

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

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 aconstvariable that points to anArray?

A

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 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 const until you need to reassign the value of the variable, then use let

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

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

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

What is “string interpolation”?

A

Insert, or interpolate, variables into strings using template literals. Use placeholders of the form ${expression} to perform substitutions for embedded expressions

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

What is destructuring, conceptually?

A

Unpack values from arrays, or properties from objects, into distinct variables

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

What is the syntax forObjectdestructuring?

A

const { var1, var2: varAlias2 } = obj

Use (:) colon to rename variable

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

What is the syntax forArraydestructuring?

A

const [var1, var2, var3] = arr

Use (,) to skip elements in 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 creatingObject/Arrayliterals?

A

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

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

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

param => exp; // implicit return

() => exp;

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

Function body evaluated as an expression and implicit return

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

How is the value ofthisdetermined within an arrow function?

A

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

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

17
Q

How do you handle the fulfillment of a Promise?

A

.then((value) => { /* fulfillment handler */ })

18
Q

How do you handle the rejection of a Promise?

A

.then((reason) => { /* rejection handler */ })

19
Q

What isArray.prototype.filteruseful for?

A

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

20
Q

What isArray.prototype.mapuseful 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 isArray.prototype.reduceuseful for?

A

Takes all of the elements in an array and reduces them into a single value

22
Q

What is “syntactic sugar”?

A

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.

23
Q

What is thetypeofan ES6 class?

A

function

24
Q

Describe ES6 class syntax.

A
class className {
  constructor(parameter) {
    // constructor code block;
  }
  method() {
    // method code block;
  }
}
25
Q

What is “refactoring”?

A

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.

26
Q

How are ES Modules different from CommonJS modules?

A

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.

27
Q

What kind of modules can Webpack support?

A

ECMAScript modules, CommonJS modules, and AMD modules.